XmlAttributeCollection.ItemOf[] 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取具有指定名称或索引的特性。
重载
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.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
XmlDocument^ doc = gcnew 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();
}
}
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
注解
此属性是文档对象模型 (DOM) 的 Microsoft 扩展。 它等效于调用 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.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
XmlDocument^ doc = gcnew 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 );
}
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
注解
此属性是文档对象模型 (DOM) 的 Microsoft 扩展。 它等效于调用 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
。
注解
此属性是文档对象模型 (DOM) 的 Microsoft 扩展。 它等效于调用 GetNamedItem。