XmlNode.Item[] 屬性

定義

取得指定的子項目。

多載

Item[String]

取得具有指定的 Name 的第一個子項目。

Item[String, String]

取得具有指定的 LocalNameNamespaceURI 的第一個子項目。

Item[String]

取得具有指定的 Name 的第一個子項目。

public:
 virtual property System::Xml::XmlElement ^ default[System::String ^] { System::Xml::XmlElement ^ get(System::String ^ name); };
public virtual System.Xml.XmlElement this[string name] { get; }
public virtual System.Xml.XmlElement? this[string name] { get; }
member this.Item(string) : System.Xml.XmlElement
Default Public Overridable ReadOnly Property Item(name As String) As XmlElement

參數

name
String

要擷取的項目的限定名稱 (Qualified Name)。

屬性值

XmlElement

符合指定名稱的第一個 XmlElement。 如果沒有相符項目,則傳回 null 參考 (在 Visual Basic 中為 Nothing)。

範例

下列範例會顯示 title 元素。

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
{
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<book ISBN='1-861001-57-5'>"
   "<title>Pride And Prejudice</title>"
   "<price>19.95</price>"
   "</book>" );
   XmlNode^ root = doc->FirstChild;
   Console::WriteLine( "Display the title element..." );
   Console::WriteLine( root[ "title" ]->OuterXml );
}
using System;
using System.IO;
using System.Xml;

public class Sample {

  public static void Main() {

    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<book ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +
                "<price>19.95</price>" +
                "</book>");

    XmlNode root = doc.FirstChild;

    Console.WriteLine("Display the title element...");
    Console.WriteLine(root["title"].OuterXml);
  }
}
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    Public Shared Sub Main()
        
        Dim doc As New XmlDocument()
        doc.LoadXml("<book ISBN='1-861001-57-5'>" & _
                    "<title>Pride And Prejudice</title>" & _ 
                    "<price>19.95</price>" & _ 
                    "</book>")

        Dim root As XmlNode = doc.FirstChild
        Console.WriteLine("Display the title element...")
        Console.WriteLine(root("title").OuterXml)
    End Sub
End Class

備註

這個屬性是文件物件模型的 Microsoft 擴充功能。

適用於

Item[String, String]

取得具有指定的 LocalNameNamespaceURI 的第一個子項目。

public:
 virtual property System::Xml::XmlElement ^ default[System::String ^, System::String ^] { System::Xml::XmlElement ^ get(System::String ^ localname, System::String ^ ns); };
public virtual System.Xml.XmlElement this[string localname, string ns] { get; }
public virtual System.Xml.XmlElement? this[string localname, string ns] { get; }
member this.Item(string * string) : System.Xml.XmlElement
Default Public Overridable ReadOnly Property Item(localname As String, ns As String) As XmlElement

參數

localname
String

項目的本機名稱。

ns
String

項目的命名空間 URI。

屬性值

XmlElement

具有符合的 localnamens 的第一個 XmlElement。 如果沒有相符項目,則傳回 null 參考 (在 Visual Basic 中為 Nothing)。

備註

這個屬性是文件物件模型的 Microsoft 擴充功能。

適用於