XmlNode.Item[] 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得指定的子元素。
多載
| 名稱 | Description |
|---|---|
| Item[String] |
取得第一個子元素,指定為 Name。 |
| Item[String, String] |
取得第一個子元素,且指定為 LocalNameNamespaceURI。 |
Item[String]
- 來源:
- XmlNode.cs
- 來源:
- XmlNode.cs
- 來源:
- XmlNode.cs
- 來源:
- XmlNode.cs
- 來源:
- XmlNode.cs
取得第一個子元素,指定為 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
要取回的元素的限定名稱。
屬性值
第一個 XmlElement 和指定名稱相符的。 若無匹配,則回傳空參考(Nothing in Visual Basic)。
範例
以下範例顯示標題元素。
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 對文件物件模型(DOM)的擴充。
適用於
Item[String, String]
- 來源:
- XmlNode.cs
- 來源:
- XmlNode.cs
- 來源:
- XmlNode.cs
- 來源:
- XmlNode.cs
- 來源:
- XmlNode.cs
取得第一個子元素,且指定為 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 是匹配 localname 和 ns。 若無匹配,則回傳空參考(Nothing in Visual Basic)。
備註
此屬性是 Microsoft 對文件物件模型(DOM)的擴充。