XmlAttributeAttribute.AttributeName プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XmlAttributeAttribute.AttributeName プロパティの意味・解説 

XmlAttributeAttribute.AttributeName プロパティ

XML 属性の名前を取得または設定します

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

Dim instance As XmlAttributeAttribute
Dim value As String

value = instance.AttributeName

instance.AttributeName = value
public string AttributeName { get;
 set; }
public:
property String^ AttributeName {
    String^ get ();
    void set (String^ value);
}
/** @property */
public String get_AttributeName ()

/** @property */
public void set_AttributeName (String value)
public function get AttributeName
 () : String

public function set AttributeName
 (value : String)

プロパティ
XML 属性の名前。既定値は、メンバ名です。

解説解説
使用例使用例

XmlAttributeAttribute の AttributeName プロパティ設定する例を次に示します

Option Explicit
Option Strict

Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization


Public Class Group
    ' Change the XML attribute name.
    <XmlAttribute(AttributeName := "MgrName")>
 Public Name As String
    ' Use the AttributeName to collect all the XML attributes
    ' in the XML-document instance. 
    <XmlAttribute(AttributeName := "*")> Public
 Attrs() As XmlAttribute
End Class

Public Class Run
    
    Public Shared Sub Main()
        Dim test As New
 Run()
        ' To use the AttributeName to collect all the
        ' XML attributes. Call SerializeObject to generate
        ' an XML document and alter the document by adding
        ' new XML attributes to it. Then comment out the SerializeObject
        ' method, and call DeserializeObject.
        test.SerializeObject("MyAtts.xml")
        test.DeserializeObject("MyAtts.xml")
    End Sub
    
    Public Sub SerializeObject(ByVal
 filename As String)
        Console.WriteLine("Serializing")
        ' Create an instance of the XmlSerializer class.
        Dim mySerializer As New
 XmlSerializer(GetType(Group))
        ' Writing the file requires a TextWriter.
        Dim writer As New
 StreamWriter(filename)
        ' Create an instance of the class that will be serialized.
        Dim myGroup As New
 Group()
        ' Set the Name property, which will be generated
        ' as an XML attribute. 
        myGroup.Name = "Wallace"
        ' Serialize the class, and close the TextWriter.
        mySerializer.Serialize(writer, myGroup)
        writer.Close()
    End Sub
        
    Public Sub DeserializeObject(ByVal
 filename As String)
        Console.WriteLine("Deserializing")
        Dim mySerializer As New
 XmlSerializer(GetType(Group))
        Dim fs As New FileStream(filename,
 FileMode.Open)
        Dim myGroup As Group = CType(mySerializer.Deserialize(fs),
 Group)
        ' The following code prints all the attributes in the
        ' XML document. To collect the attributes, the AttributeName
 of the
        ' XmlAttributeAttribute must be set to "*".
        Dim xAtt As XmlAttribute
        For Each xAtt In
  myGroup.Attrs
            Console.WriteLine(xAtt.Name & ":"
 & xAtt.Value)
        Next xAtt
    End Sub
End Class

using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
public class Group
{
   // Change the XML attribute name.
   [XmlAttribute(AttributeName = "MgrName")]
   public string Name;
   /* Use the AttributeName to collect all the XML attributes
   in the XML-document instance. */
}

public class Run
{
   public static void Main()
   {
      Run test = new Run();
      /* To use the AttributeName to collect all the
      XML attributes. Call SerializeObject to generate 
      an XML document and alter the document by adding
      new XML attributes to it. Then comment out the SerializeObject
      method, and call DeserializeObject. */
      test.SerializeObject("MyAtts.xml");
      test.DeserializeObject("MyAtts.xml");
}
public void SerializeObject(string
 filename)
{
   Console.WriteLine("Serializing");
   // Create an instance of the XmlSerializer class.
   XmlSerializer mySerializer =  new XmlSerializer(typeof(Group));
   // Writing the file requires a TextWriter.
   TextWriter writer = new StreamWriter(filename);
   // Create an instance of the class that will be serialized.
   Group myGroup = new Group();
   /* Set the Name property, which will be generated
   as an XML attribute. */
   myGroup.Name = "Wallace";
   // Serialize the class, and close the TextWriter.
   mySerializer.Serialize(writer, myGroup);
   writer.Close();
}

   public void DeserializeObject(string
 filename)
   {
      Console.WriteLine("Deserializing");
      XmlSerializer mySerializer =
      new XmlSerializer(typeof(Group));
      FileStream fs = new FileStream(filename, FileMode.Open);
      Group myGroup = (Group)
      mySerializer.Deserialize(fs);
      Console.WriteLine(myGroup.Name);
   }
}
   
#using <System.Xml.dll>
#using <System.dll>

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

public ref class Group
{
public:

   // Change the XML attribute name.

   [XmlAttributeAttribute(AttributeName="MgrName")]
   String^ Name;
   /* Use the AttributeName to collect all the XML attributes
      in the XML-document instance. */
};

void SerializeObject( String^ filename )
{
   Console::WriteLine( "Serializing" );

   // Create an instance of the XmlSerializer class.
   XmlSerializer^ mySerializer = gcnew XmlSerializer( Group::typeid );

   // Writing the file requires a TextWriter.
   TextWriter^ writer = gcnew StreamWriter( filename );

   // Create an instance of the class that will be serialized.
   Group^ myGroup = gcnew Group;

   /* Set the Name property, which will be generated
      as an XML attribute. */
   myGroup->Name = "Wallace";

   // Serialize the class, and close the TextWriter.
   mySerializer->Serialize( writer, myGroup );
   writer->Close();
}

void DeserializeObject( String^ filename )
{
   Console::WriteLine( "Deserializing" );
   XmlSerializer^ mySerializer = gcnew XmlSerializer( Group::typeid );
   FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
   Group^ myGroup = dynamic_cast<Group^>(mySerializer->Deserialize( fs ));
   Console::WriteLine( myGroup->Name );
}

int main()
{
   /* To use the AttributeName to collect all the
      XML attributes. Call SerializeObject to generate 
      an XML document and alter the document by adding
      new XML attributes to it. Then comment out the SerializeObject
      method, and call DeserializeObject. */
   SerializeObject( "MyAtts.xml" );
   DeserializeObject( "MyAtts.xml" );
}
import System.*;
import System.IO.*;
import System.Xml.*;
import System.Xml.Serialization.*;

public class Group
{
    // Change the XML attribute name.
    /** @attribute XmlAttribute(AttributeName = "MgrName")
     */
    public String name;
    /* Use the AttributeName to collect all the XML attributes
       in the XML-document instance.
     */
} //Group

public class Run
{
    public static void main(String[]
 args)
    {
        Run test = new Run();
        /* To use the AttributeName to collect all the
           XML attributes. Call SerializeObject to generate 
           an XML document and alter the document by adding
           new XML attributes to it. Then comment out the SerializeObject
           method, and call DeserializeObject.
         */
        test.SerializeObject("MyAtts.xml");
        test.DeserializeObject("MyAtts.xml");
    } //main

    public void SerializeObject(String fileName)
    {
        Console.WriteLine("Serializing");
        // Create an instance of the XmlSerializer class.
        XmlSerializer mySerializer = new XmlSerializer(Group.class.ToType());
        // Writing the file requires a TextWriter.
        TextWriter writer = new StreamWriter(fileName);
        // Create an instance of the class that will be serialized.
        Group myGroup = new Group();
        /* Set the Name property, which will be generated
           as an XML attribute.
         */
        myGroup.name = "Wallace";
        // Serialize the class, and close the TextWriter.
        mySerializer.Serialize(writer, myGroup);
        writer.Close();
    } //SerializeObject

    public void DeserializeObject(String fileName)
    {
        Console.WriteLine("Deserializing");
        XmlSerializer mySerializer = new XmlSerializer(Group.class.ToType());
        FileStream fs = new FileStream(fileName, FileMode.Open);
        Group myGroup = (Group)mySerializer.Deserialize(fs);
        Console.WriteLine(myGroup.name);
    } //DeserializeObject
} //Run
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlAttributeAttribute クラス
XmlAttributeAttribute メンバ
System.Xml.Serialization 名前空間
ElementName



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

辞書ショートカット

すべての辞書の索引

「XmlAttributeAttribute.AttributeName プロパティ」の関連用語

XmlAttributeAttribute.AttributeName プロパティのお隣キーワード
検索ランキング

   

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



XmlAttributeAttribute.AttributeName プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS