次の方法で共有


XmlAttributeCollection.ItemOf プロパティ (String)

指定した名前の属性を取得します。

[C#] C# では、このプロパティは XmlAttributeCollection クラスのインデクサになります。

Overloads Public Overridable Default ReadOnly Property ItemOf( _
   ByVal name As String _) As XmlAttribute
[C#]
public virtual XmlAttribute this[stringname] {get;}
[C++]
public: __property virtual XmlAttribute* get_ItemOf(String* name);
[JScript]
returnValue = XmlAttributeCollectionObject.ItemOf(name);またはreturnValue = XmlAttributeCollectionObject(name);

[JScript] JScript では、この型で定義されている既定のインデックス プロパティを使用することができます。しかし、独自のインデックス プロパティを明示的に定義することはできません。ただし、このクラスの expando 属性を指定すると、既定のインデックス プロパティが提供されます。提供されるインデックス プロパティの型は Object 型であり、インデックス型は String になります。

引数 [JScript]

  • name
    属性の限定名。

パラメータ [Visual Basic, C#, C++]

  • name
    属性の限定名。

プロパティ値

指定した名前を持つ XmlAttribute

解説

このプロパティは、DOM (Document Object Model) に対する Microsoft 拡張機能です。これは GetNamedItem の呼び出しと等価です。

使用例

[Visual Basic, C#, C++] ドキュメントから属性を削除する例を次に示します。

 
Imports System
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

[C#] 
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);  
  }
}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
{
    XmlDocument* doc = new XmlDocument();
    doc->LoadXml(S"<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->ItemOf[S"genre"]);

    Console::WriteLine(S"Display the modified XML...\r\n");
    Console::WriteLine(doc->OuterXml);  
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

XmlAttributeCollection クラス | XmlAttributeCollection メンバ | System.Xml 名前空間 | XmlAttributeCollection.Item オーバーロードの一覧