XmlAttributeCollection.ItemOf[] 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得指定名稱或索引的屬性。
多載
| 名稱 | Description |
|---|---|
| ItemOf[Int32] |
取得具有指定索引的屬性。 |
| ItemOf[String] |
取得指定名稱的屬性。 |
| ItemOf[String, String] |
取得具有指定本地名稱與命名空間的屬性,統一資源識別碼(URI)。 |
ItemOf[Int32]
取得具有指定索引的屬性。
public:
property System::Xml::XmlAttribute ^ default[int] { System::Xml::XmlAttribute ^ get(int i); };
public:
virtual property System::Xml::XmlAttribute ^ default[int] { System::Xml::XmlAttribute ^ get(int i); };
public System.Xml.XmlAttribute this[int i] { get; }
public virtual System.Xml.XmlAttribute this[int i] { get; }
member this.ItemOf(int) : System.Xml.XmlAttribute
Default Public ReadOnly Property ItemOf(i As Integer) As XmlAttribute
Default Public Overridable ReadOnly Property ItemOf(i As Integer) As XmlAttribute
參數
- i
- Int32
屬性的索引。
屬性值
屬性位於指定索引。
例外狀況
輸入的索引超出範圍。
範例
以下範例顯示集合中的所有屬性。
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main(){
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +
"</book>");
//Create an attribute collection.
XmlAttributeCollection attrColl = doc.DocumentElement.Attributes;
Console.WriteLine("Display all the attributes in the collection...\r\n");
for (int i=0; i < attrColl.Count; i++)
{
Console.Write("{0} = ", attrColl[i].Name);
Console.Write("{0}", attrColl[i].Value);
Console.WriteLine();
}
}
}
Imports System.IO
Imports System.Xml
public class Sample
public shared sub Main()
Dim doc as XmlDocument = new XmlDocument()
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" & _
"<title>Pride And Prejudice</title>" & _
"</book>")
'Create an attribute collection.
Dim attrColl as XmlAttributeCollection = doc.DocumentElement.Attributes
Console.WriteLine("Display all the attributes in the collection...")
Dim i as integer
for i=0 to attrColl.Count-1
Console.Write("{0} = ", attrColl.ItemOf(i).Name)
Console.Write("{0}", attrColl.ItemOf(i).Value)
Console.WriteLine()
next
end sub
end class
備註
此屬性是 Microsoft 對文件物件模型(DOM)的擴充。 它等價於呼叫 XmlNamedNodeMap.Item。
另請參閱
適用於
ItemOf[String]
取得指定名稱的屬性。
public:
property System::Xml::XmlAttribute ^ default[System::String ^] { System::Xml::XmlAttribute ^ get(System::String ^ name); };
public:
virtual property System::Xml::XmlAttribute ^ default[System::String ^] { System::Xml::XmlAttribute ^ get(System::String ^ name); };
public System.Xml.XmlAttribute this[string name] { get; }
public System.Xml.XmlAttribute? this[string name] { get; }
public virtual System.Xml.XmlAttribute this[string name] { get; }
member this.ItemOf(string) : System.Xml.XmlAttribute
Default Public ReadOnly Property ItemOf(name As String) As XmlAttribute
Default Public Overridable ReadOnly Property ItemOf(name As String) As XmlAttribute
參數
- name
- String
屬性的限定名稱。
屬性值
該屬性名稱為指定名稱。 若該屬性不存在,則此性質回傳 null。
範例
以下範例是從文件中移除一個屬性。
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main(){
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +
"</book>");
//Create an attribute collection and remove an attribute
//from the collection.
XmlAttributeCollection attrColl = doc.DocumentElement.Attributes;
attrColl.Remove(attrColl["genre"]);
Console.WriteLine("Display the modified XML...\r\n");
Console.WriteLine(doc.OuterXml);
}
}
Imports System.IO
Imports System.Xml
public class Sample
public shared sub Main()
Dim doc as XmlDocument = new XmlDocument()
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" & _
"<title>Pride And Prejudice</title>" & _
"</book>")
'Create an attribute collection and remove an attribute
'from the collection.
Dim attrColl as XmlAttributeCollection = doc.DocumentElement.Attributes
attrColl.Remove(attrColl.ItemOf("genre"))
Console.WriteLine("Display the modified XML...")
Console.WriteLine(doc.OuterXml)
end sub
end class
備註
此屬性是 Microsoft 對文件物件模型(DOM)的擴充。 它等價於呼叫 GetNamedItem。
適用於
ItemOf[String, String]
取得具有指定本地名稱與命名空間的屬性,統一資源識別碼(URI)。
public:
property System::Xml::XmlAttribute ^ default[System::String ^, System::String ^] { System::Xml::XmlAttribute ^ get(System::String ^ localName, System::String ^ namespaceURI); };
public:
virtual property System::Xml::XmlAttribute ^ default[System::String ^, System::String ^] { System::Xml::XmlAttribute ^ get(System::String ^ localName, System::String ^ namespaceURI); };
public System.Xml.XmlAttribute this[string localName, string namespaceURI] { get; }
public System.Xml.XmlAttribute? this[string localName, string? namespaceURI] { get; }
public virtual System.Xml.XmlAttribute this[string localName, string namespaceURI] { get; }
member this.ItemOf(string * string) : System.Xml.XmlAttribute
Default Public ReadOnly Property ItemOf(localName As String, namespaceURI As String) As XmlAttribute
Default Public Overridable ReadOnly Property ItemOf(localName As String, namespaceURI As String) As XmlAttribute
參數
- localName
- String
該屬性的當地名稱。
- namespaceURI
- String
屬性的命名空間 URI。
屬性值
具有指定本地名稱與命名空間 URI 的屬性。 若該屬性不存在,則此性質回傳 null。
備註
此屬性是 Microsoft 對文件物件模型(DOM)的擴充。 它等價於呼叫 GetNamedItem。