XmlAnyAttributeAttribute クラスとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XmlAnyAttributeAttribute クラスの意味・解説 

XmlAnyAttributeAttribute クラス

メンバ (XmlAttribute オブジェクト配列返すフィールド) に任意の XML 属性含めることができるように指定します

名前空間: System.Xml.Serialization
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

<AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field
 Or AttributeTargets.Parameter Or AttributeTargets.ReturnValue,
 AllowMultiple:=False)> _
Public Class XmlAnyAttributeAttribute
    Inherits Attribute
Dim instance As XmlAnyAttributeAttribute
[AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue,
 AllowMultiple=false)] 
public class XmlAnyAttributeAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Property|AttributeTargets::Field|AttributeTargets::Parameter|AttributeTargets::ReturnValue,
 AllowMultiple=false)] 
public ref class XmlAnyAttributeAttribute :
 public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue,
 AllowMultiple=false) */ 
public class XmlAnyAttributeAttribute extends
 Attribute
AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue,
 AllowMultiple=false) 
public class XmlAnyAttributeAttribute extends
 Attribute
解説解説

XML ドキュメント含まれるメタデータなど、XML ドキュメント一部として送信される可能性がある任意のデータXML 属性として含めるには、XmlAnyAttributeAttribute使用します

XmlAnyAttributeAttribute は、XmlAttribute オブジェクトまたは XmlNode オブジェクト配列返すフィールド適用します。XmlSerializer クラスの Deserialize メソッド呼び出されると、逆シリアル化対象クラス内に対応するメンバがない XML 属性はすべて、配列にまとめられます。シリアル化終了したら、XmlAttribute 項目のコレクション反復処理して、データを処理できます

XmlAnyAttributeAttributeクラスメンバ適用すると、XmlSerializer の UnknownNode イベントと UnknownAttribute イベント発生しなくなります

メモメモ

コードでは、XmlAnyAttributeAttribute代わりに XmlAnyAttribute という短い語使用できます

属性使用方法については、「属性使用したメタデータ拡張」を参照してください

使用例使用例

不明な属性をすべて XmlAttribute オブジェクト配列にまとめる例を次に示します。このサンプル コード実行するには、次の XML含んだ UnknownAttributes.xml という名前のファイル作成します

 <?xml version="1.0" encoding="utf-8"?>
 <Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 GroupType = 'Technical' GroupNumber = '42' GroupBase = 'Red'>
   <GroupName>MyGroup</GroupName>
 </Group>
Imports System
Imports System.IO
Imports System.Xml.Serialization
Imports System.Xml

Public Class Group
   Public GroupName As String
 
   ' The UnknownAttributes array will be used to collect all unknown
   ' attributes found when deserializing.
   <XmlAnyAttribute> _
    Public UnknownAttributes()As XmlAttribute
End Class

Public Class Test
   Shared Sub Main()
      Dim t  As Test = New
 Test()
      ' Deserialize the file containing unknown attributes.
      t.DeserializeObject("UnknownAttributes.xml")
   End Sub

   Private Sub DeserializeObject(filename As
 String)
      Dim ser As XmlSerializer = New
 XmlSerializer(GetType(Group))
      ' A FileStream is needed to read the XML document.
     Dim fs As FileStream = New
 FileStream(filename, FileMode.Open)
     Dim g As Group = CType(ser.Deserialize(fs),
 Group)
     fs.Close()
     ' Write out the data, including unknown attributes.
     Console.WriteLine(g.GroupName)
     Console.WriteLine("Number of unknown attributes: "
 & _ 
     g.UnknownAttributes.Length)
     Dim xAtt As XmlAttribute
     for each xAtt in g.UnknownAttributes
        Console.WriteLine(xAtt.Name & ": " &
 xAtt.InnerXml)
     Next
     ' Serialize the object again with the attributes added.
     Me.SerializeObject("AttributesAdded.xml"
,g)
   End Sub

   Private Sub SerializeObject(filename As
 String, g As object)
      Dim ser As XmlSerializer = New
 XmlSerializer(GetType(Group))
      DIm writer As TextWriter = New
 StreamWriter(filename)
      ser.Serialize(writer, g)
      writer.Close()
   End Sub
End Class
using System;
using System.IO;
using System.Xml.Serialization;
using System.Xml;

public class Group{
   public string GroupName;
   // The UnknownAttributes array will be used to collect all unknown
   // attributes found when deserializing.
   [XmlAnyAttribute]
    public XmlAttribute[]XAttributes;
}

public class Test{
   static void Main(){
      Test t = new Test();
      // Deserialize the file containing unknown attributes.

      t.DeserializeObject("UnknownAttributes.xml");
   }

   private void DeserializeObject(string
 filename){
      XmlSerializer ser = new XmlSerializer(typeof(Group));
      // A FileStream is needed to read the XML document.
     FileStream fs = new FileStream(filename, FileMode.Open);
     Group g = (Group) ser.Deserialize(fs);
     fs.Close();
     // Write out the data, including unknown attributes.
     Console.WriteLine(g.GroupName);
     Console.WriteLine("Number of unknown attributes: " + 
     g.XAttributes.Length);
     foreach(XmlAttribute xAtt in g.XAttributes){
     Console.WriteLine(xAtt.Name + ": " + xAtt.InnerXml);
     }
     // Serialize the object again with the attributes added.
     this.SerializeObject("AttributesAdded.xml",g);
   }

   private void SerializeObject(string
 filename, object g){
      XmlSerializer ser = new XmlSerializer(typeof(Group));
      TextWriter writer = new StreamWriter(filename);
      ser.Serialize(writer, g);
      writer.Close();
   }
}
#using <System.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::Collections;
using namespace System::IO;
using namespace System::Xml::Serialization;
using namespace System::Xml;

public ref class Group
{
public:
   String^ GroupName;

   // The UnknownAttributes array will be used to collect all unknown
   // attributes found when deserializing.

   [XmlAnyAttributeAttribute]
   array<XmlAttribute^>^XAttributes;
};

void SerializeObject( String^ filename, Object^ g )
{
   XmlSerializer^ ser = gcnew XmlSerializer( Group::typeid );
   TextWriter^ writer = gcnew StreamWriter( filename );
   ser->Serialize( writer, g );
   writer->Close();
}

void DeserializeObject( String^ filename )
{
   XmlSerializer^ ser = gcnew XmlSerializer( Group::typeid );

   // A FileStream is needed to read the XML document.
   FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
   Group^ g = safe_cast<Group^>(ser->Deserialize( fs ));
   fs->Close();

   // Write out the data, including unknown attributes.
   Console::WriteLine( g->GroupName );
   Console::WriteLine(  "Number of unknown attributes: {0}", g->XAttributes->Length
 );
   for ( IEnumerator ^ e = g->XAttributes->GetEnumerator();
 e->MoveNext();  )
   {
      XmlAttribute^ xAtt = safe_cast<XmlAttribute^>(e->Current);
      Console::WriteLine( "{0}: {1}", xAtt->Name, xAtt->InnerXml
 );
   }
   SerializeObject( "AttributesAdded.xml", g );
}

int main()
{
   // Deserialize the file containing unknown attributes.
   DeserializeObject(  "UnknownAttributes.xml" );
}

import System.*;
import System.IO.*;
import System.Xml.Serialization.*;
import System.Xml.*;
public class Group
{
    public String groupName;

    // The UnknownAttributes array will be used to collect all unknown
    // attributes found when deserializing.
    /** @attribute XmlAnyAttribute()
     */
    public XmlAttribute xAttributes[];
} //Group

public class Test
{
    public static void main(String[]
 args)
    {
        Test t = new Test();
        // Deserialize the file containing unknown attributes.
        t.DeserializeObject("UnknownAttributes.xml");
    } //main

    private void DeserializeObject(String fileName)
    {
        XmlSerializer ser = new XmlSerializer(Group.class.ToType());
        // A FileStream is needed to read the XML document.
        FileStream fs = new FileStream(fileName, FileMode.Open);
        Group g = (Group)ser.Deserialize(fs);
        fs.Close();
        // Write out the data, including unknown attributes.
        Console.WriteLine(g.groupName);
        Console.WriteLine("Number of unknown attributes: " 
            + g.xAttributes.get_Length());
        for (int iCtr = 0; iCtr < g.xAttributes.get_Count();
 iCtr++) {
            XmlAttribute xAtt = (XmlAttribute)g.xAttributes.get_Item(iCtr);
            Console.WriteLine(xAtt.get_Name() + ": " + xAtt.get_InnerXml());
        }
        // Serialize the object again with the attributes added.
        this.SerializeObject("AttributesAdded.xml",
 g);
    } //DeserializeObject

    private void SerializeObject(String fileName,
 Object g)
    {
        XmlSerializer ser = new XmlSerializer(Group.class.ToType());
        TextWriter writer = new StreamWriter(fileName);
        ser.Serialize(writer, g);
        writer.Close();
    } //SerializeObject
} //Test
継承階層継承階層
System.Object
   System.Attribute
    System.Xml.Serialization.XmlAnyAttributeAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlAnyAttributeAttribute メンバ
System.Xml.Serialization 名前空間
XmlAnyElementAttribute
XmlSerializer
XmlAttributes
その他の技術情報
XML シリアル化概要
方法 : XML ストリーム代替要素名を指定する
属性使用した XML シリアル化制御
XML シリアル化の例
XML スキーマ定義ツール (Xsd.exe)



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「XmlAnyAttributeAttribute クラス」の関連用語

XmlAnyAttributeAttribute クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



XmlAnyAttributeAttribute クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS