XmlNode.Item[] 属性  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取指定的子元素。
重载
| Item[String] | 获取具有指定 Name 的第一个子元素。 | 
| Item[String, String] | 获取具有指定 LocalName 和 NamespaceURI 的第一个子元素。 | 
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.XmlElementDefault Public Overridable ReadOnly Property Item(name As String) As XmlElement参数
- name
- String
要检索的元素的限定名。
属性值
与指定名称匹配的第一个 XmlElement。 如果没有匹配项,则它返回空引用(在 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
注解
此属性是文档对象模型 (DOM) 的 Microsoft 扩展。
适用于
Item[String, String]
获取具有指定 LocalName 和 NamespaceURI 的第一个子元素。
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.XmlElementDefault Public Overridable ReadOnly Property Item(localname As String, ns As String) As XmlElement参数
- localname
- String
元素的本地名称。
- ns
- String
元素的命名空间 URI。
属性值
具有匹配的 localname 和 ns 的第一个 XmlElement。 如果没有匹配项,则它返回空引用(在 Visual Basic 中为 Nothing)。
注解
此属性是文档对象模型 (DOM) 的 Microsoft 扩展。