XmlReader.IsStartElement メソッド

定義

現在のコンテンツ ノードが開始タグかどうかをテストします。

オーバーロード

IsStartElement(String, String)

MoveToContent() を呼び出し、現在のコンテンツ ノードが開始タグまたは空の要素タグかどうか、また、見つかった要素の LocalName プロパティと NamespaceURI プロパティが、指定した文字列と一致するかどうかをテストします。

IsStartElement()

MoveToContent() を呼び出し、現在のコンテンツ ノードが開始タグまたは空の要素タグかどうかをテストします。

IsStartElement(String)

MoveToContent() を呼び出し、現在のコンテンツ ノードが開始タグまたは空の要素タグかどうか、また、見つかった要素の Name プロパティが、指定した引数と一致するかどうかをテストします。

IsStartElement(String, String)

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 プロパティと一致する文字列。

戻り値

見つかったノードが要素の場合は trueXmlNodeType.Element 以外のノード型が見つかった場合、または要素の LocalName および NamespaceURI プロパティが指定した文字列と一致しない場合は 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() が開始タグまたは空の要素タグを見つけた場合は trueXmlNodeType.Element 以外のノード型が見つかった場合は false

例外

入力ストリームで、正しくない 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 プロパティと一致する文字列。

戻り値

見つかったノードが要素であり、Name プロパティが指定した文字列と一致する場合は trueXmlNodeType.Element 以外のノード型が見つかった場合、または要素の Name プロパティが指定した文字列と一致しない場合は false

例外

入力ストリームで、正しくない XML が検出されました。

先行の非同期操作が完了する前に、XmlReader メソッドが呼び出されました。 この場合、「非同期操作が既に実行されています」というメッセージと共に InvalidOperationException がスローされます。

次の例では、各 price 要素を表示します。

// 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

注釈

このメソッドは、リーダーがコンテンツ ノードに配置されるまで、空白、コメント、および処理命令をスキップします。 次に、 メソッドは、現在のノードが 要素であるかどうかをテストします。

こちらもご覧ください

適用対象