XmlReader.IsStartElement 方法

定義

測試目前的內容節點是否為開頭標記。

多載

IsStartElement(String, String)

呼叫 MoveToContent() 並測試目前的內容節點為開頭標記或空白項目標記,以及所找到項目的 LocalNameNamespaceURI 屬性是否符合指定的字串。

IsStartElement()

呼叫 MoveToContent() 並測試目前的內容節點為開頭標記或空白項目標記。

IsStartElement(String)

呼叫 MoveToContent() 並測試目前的內容節點為開頭標記或空白項目標記,以及所找到項目的 Name 屬性是否符合指定的引數。

IsStartElement(String, String)

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

呼叫 MoveToContent() 並測試目前的內容節點為開頭標記或空白項目標記,以及所找到項目的 LocalNameNamespaceURI 屬性是否符合指定的字串。

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如果產生的節點是項目。 如果找到的節點類型並非 XmlNodeType.Element,或項目的 LocalNameNamespaceURI 屬性不符合指定字串,即為 false

例外狀況

在輸入資料流中遇到錯誤的 XML。

在先前的非同步作業完成前呼叫了 XmlReader 方法。 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。

備註

這個方法會略過空白字元、批註和處理指示,直到讀取器位於內容節點上為止。 方法接著會測試目前節點是否為 專案。

另請參閱

適用於

IsStartElement()

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

傳回

如果 MoveToContent() 找到開頭標記或空白項目標記,即為 true;如果找到的節點類型並非 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

呼叫 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。 如果找到的節點類型並非 XmlNodeType.Element,或項目 Name 屬性不符合指定字串,即為 false

例外狀況

在輸入資料流中遇到錯誤的 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

備註

這個方法會略過空白字元、批註和處理指示,直到讀取器位於內容節點上為止。 方法接著會測試目前節點是否為 專案。

另請參閱

適用於