XmlReader.IsStartElement 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
测试当前内容节点是否为开始标记。
重载
| 名称 | 说明 |
|---|---|
| IsStartElement(String, String) |
调用MoveToContent()并测试当前内容节点是否为开始标记或空元素标记,以及找到的元素的和LocalName属性是否NamespaceURI与给定字符串匹配。 |
| IsStartElement() |
调用 MoveToContent() 和测试当前内容节点是否为开始标记或空元素标记。 |
| IsStartElement(String) |
调用 MoveToContent() 和测试当前内容节点是否为开始标记或空元素标记,以及找到的元素的属性是否 Name 与给定参数匹配。 |
IsStartElement(String, String)
- Source:
- XmlReader.cs
- Source:
- XmlReader.cs
- Source:
- XmlReader.cs
- Source:
- XmlReader.cs
- Source:
- XmlReader.cs
调用MoveToContent()并测试当前内容节点是否为开始标记或空元素标记,以及找到的元素的和LocalName属性是否NamespaceURI与给定字符串匹配。
public:
virtual bool IsStartElement(System::String ^ localname, System::String ^ ns);
public virtual bool IsStartElement(string localname, string ns);
abstract member IsStartElement : string * string -> bool
override this.IsStartElement : string * string -> bool
Public Overridable Function IsStartElement (localname As String, ns As String) As Boolean
参数
- localname
- String
要与 LocalName 找到的元素的属性匹配的字符串。
- ns
- String
要与 NamespaceURI 找到的元素的属性匹配的字符串。
返回
true 如果生成的节点是元素,则为 。
false 如果找到的 XmlNodeType.Element 节点类型,或者 LocalName 元素的 and NamespaceURI 属性与指定的字符串不匹配,则为 。
例外
输入流中遇到不正确的 XML。
在上一个异步操作完成之前调用了一个 XmlReader 方法。 在这种情况下, InvalidOperationException 会引发消息“正在进行异步操作”。
注解
此方法跳过空白、注释和处理指令,直到读取器定位在内容节点上。 然后,该方法测试当前节点是否为元素。
另请参阅
适用于
IsStartElement()
- Source:
- XmlReader.cs
- Source:
- XmlReader.cs
- Source:
- XmlReader.cs
- Source:
- XmlReader.cs
- Source:
- XmlReader.cs
调用 MoveToContent() 和测试当前内容节点是否为开始标记或空元素标记。
public:
virtual bool IsStartElement();
public virtual bool IsStartElement();
abstract member IsStartElement : unit -> bool
override this.IsStartElement : unit -> bool
Public Overridable Function IsStartElement () As Boolean
返回
true 如果 MoveToContent() 找到起始标记或空元素标记,则为 false ;如果找到的节点类型以外的 XmlNodeType.Element 节点类型。
例外
输入流中遇到不正确的 XML。
在上一个异步操作完成之前调用了一个 XmlReader 方法。 在这种情况下, InvalidOperationException 会引发消息“正在进行异步操作”。
示例
以下示例显示每个元素的文本内容。
while (reader.Read()) {
if (reader.IsStartElement()) {
if (reader.IsEmptyElement)
{
Console.WriteLine("<{0}/>", reader.Name);
}
else {
Console.Write("<{0}> ", reader.Name);
reader.Read(); // Read the start tag.
if (reader.IsStartElement()) // Handle nested elements.
Console.Write("\r\n<{0}>", reader.Name);
Console.WriteLine(reader.ReadString()); //Read the text content of the element.
}
}
}
While reader.Read()
If reader.IsStartElement() Then
If reader.IsEmptyElement Then
Console.WriteLine("<{0}/>", reader.Name)
Else
Console.Write("<{0}> ", reader.Name)
reader.Read() ' Read the start tag.
If reader.IsStartElement() Then ' Handle nested elements.
Console.Write(vbCr + vbLf + "<{0}>", reader.Name)
End If
Console.WriteLine(reader.ReadString()) 'Read the text content of the element.
End If
End If
End While
该示例使用该文件 elems.xml作为输入。
<book>
<title>Pride And Prejudice</title>
<price>19.95</price>
<misc/>
</book>
注解
此方法跳过空白、注释和处理指令,直到读取器定位在内容节点上。 然后,该方法测试当前节点是否为元素。
另请参阅
适用于
IsStartElement(String)
- Source:
- XmlReader.cs
- Source:
- XmlReader.cs
- Source:
- XmlReader.cs
- Source:
- XmlReader.cs
- Source:
- XmlReader.cs
调用 MoveToContent() 和测试当前内容节点是否为开始标记或空元素标记,以及找到的元素的属性是否 Name 与给定参数匹配。
public:
virtual bool IsStartElement(System::String ^ name);
public virtual bool IsStartElement(string name);
abstract member IsStartElement : string -> bool
override this.IsStartElement : string -> bool
Public Overridable Function IsStartElement (name As String) As Boolean
参数
- name
- String
与找到的元素的属性匹配 Name 的字符串。
返回
true 如果生成的节点是一个元素,并且 Name 该属性与指定的字符串匹配。
false 如果找到的 XmlNodeType.Element 节点类型或元素 Name 属性与指定的字符串不匹配,则为 。
例外
输入流中遇到不正确的 XML。
在上一个异步操作完成之前调用了一个 XmlReader 方法。 在这种情况下, InvalidOperationException 会引发消息“正在进行异步操作”。
示例
以下示例显示每个价格元素。
// Parse the file and display each price node.
while (reader.Read()) {
if (reader.IsStartElement("price")) {
Console.WriteLine(reader.ReadInnerXml());
}
}
' Parse the file and display each price node.
While reader.Read()
If reader.IsStartElement("price") Then
Console.WriteLine(reader.ReadInnerXml())
End If
End While
注解
此方法跳过空白、注释和处理指令,直到读取器定位在内容节点上。 然后,该方法测试当前节点是否为元素。