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

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

XmlRootAttribute.ElementName プロパティ

XmlSerializer クラスSerialize メソッドおよび Deserialize メソッドによって生成および認識される XML 要素名を取得または設定します

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

Dim instance As XmlRootAttribute
Dim value As String

value = instance.ElementName

instance.ElementName = value
public string ElementName { get;
 set; }
/** @property */
public String get_ElementName ()

/** @property */
public void set_ElementName (String value)
public function get ElementName
 () : String

public function set ElementName
 (value : String)

プロパティ
XML ドキュメント インスタンス生成および認識されXML ルート要素名。既定値は、シリアル化されたクラスの名前です。

解説解説

生成されXML 要素の名前をクラス名とは異なる名前にする場合は、ElementName を指定します

使用例使用例

XmlRootAttribute クラスインスタンス作成しElementName プロパティ新しい値を設定する例を次に示します次に、このオブジェクト使用してオブジェクトシリアル化オーバーライドするために使用される XmlAttributeOverrides オブジェクト作成します

Public Sub SerializeOrder(filename As
 String)
   ' Create an XmlSerializer instance using the method below.
   Dim myXmlSerializer As XmlSerializer = CreateOverrider()

   ' Create the object, and set its Name property.
   Dim myStudent As New
 Student()
   myStudent.Name = "Student class1"

   ' Serialize the class, and close the TextWriter.
   Dim writer = New StreamWriter(filename)
   myXmlSerializer.Serialize(writer, myStudent)
   writer.Close()
End Sub

' Return an XmlSerializer to override the root serialization.
Public Function CreateOverrider() As
 XmlSerializer
   ' Create an XmlAttributes to override the default root element.
   Dim myXmlAttributes As New
 XmlAttributes()

   ' Create an XmlRootAttribute and set its element name and namespace.
   Dim myXmlRootAttribute As New
 XmlRootAttribute()
   myXmlRootAttribute.ElementName = "OverriddenRootElementName"
   myXmlRootAttribute.Namespace = "http://www.microsoft.com"

   ' Set the XmlRoot property to the XmlRoot object.
   myXmlAttributes.XmlRoot = myXmlRootAttribute
   Dim myXmlAttributeOverrides As New
 XmlAttributeOverrides()

   ' Add the XmlAttributes object to the XmlAttributeOverrides object.
   myXmlAttributeOverrides.Add(GetType(Student), myXmlAttributes)

   ' Create the Serializer, and return it.
   Dim myXmlSerializer As New
 XmlSerializer(GetType(Student), myXmlAttributeOverrides)
   Return myXmlSerializer
End Function
public void SerializeOrder(string
 filename)
{
   // Create an XmlSerializer instance using the method below.
   XmlSerializer myXmlSerializer = CreateOverrider();

   // Create the object, and set its Name property.
   Student myStudent = new Student();
   myStudent.Name = "Student class1";

   // Serialize the class, and close the TextWriter.
   TextWriter writer = new StreamWriter(filename);
   myXmlSerializer.Serialize(writer, myStudent);
   writer.Close();
}

// Return an XmlSerializer to override the root serialization.
public XmlSerializer CreateOverrider()
{
   // Create an XmlAttributes to override the default root element.
   XmlAttributes myXmlAttributes = new XmlAttributes();

   // Create an XmlRootAttribute and set its element name and namespace.
   XmlRootAttribute myXmlRootAttribute = new XmlRootAttribute();
   myXmlRootAttribute.ElementName = "OverriddenRootElementName";
   myXmlRootAttribute.Namespace = "http://www.microsoft.com";

   // Set the XmlRoot property to the XmlRoot object.
   myXmlAttributes.XmlRoot = myXmlRootAttribute;
   XmlAttributeOverrides myXmlAttributeOverrides = 
                                 new XmlAttributeOverrides();
   
   /* Add the XmlAttributes object to the 
   XmlAttributeOverrides object. */
   myXmlAttributeOverrides.Add(typeof(Student), myXmlAttributes);

   // Create the Serializer, and return it.
   XmlSerializer myXmlSerializer = new XmlSerializer
      (typeof(Student), myXmlAttributeOverrides);
   return myXmlSerializer;
}
public:
   void SerializeOrder( String^ filename )
   {
      // Create an XmlSerializer instance using the method below.
      XmlSerializer^ myXmlSerializer = CreateOverrider();
      
      // Create the object, and set its Name property.
      Student^ myStudent = gcnew Student;
      myStudent->Name = "Student class1";
      
      // Serialize the class, and close the TextWriter.
      TextWriter^ writer = gcnew StreamWriter( filename );
      myXmlSerializer->Serialize( writer, myStudent );
      writer->Close();
   }

   // Return an XmlSerializer to  the root serialization.
   XmlSerializer^ CreateOverrider()
   {
      // Create an XmlAttributes to  the default root element.
      XmlAttributes^ myXmlAttributes = gcnew XmlAttributes;
      
      // Create an XmlRootAttribute and set its element name and namespace.
      XmlRootAttribute^ myXmlRootAttribute = gcnew XmlRootAttribute;
      myXmlRootAttribute->ElementName = "OverriddenRootElementName";
      myXmlRootAttribute->Namespace = "http://www.microsoft.com";
      
      // Set the XmlRoot property to the XmlRoot object.
      myXmlAttributes->XmlRoot = myXmlRootAttribute;
      XmlAttributeOverrides^ myXmlAttributeOverrides =
         gcnew XmlAttributeOverrides;
      
      // Add the XmlAttributes object to the XmlAttributeOverrides object.
      myXmlAttributeOverrides->Add( Student::typeid, myXmlAttributes );
      
      // Create the Serializer, and return it.
      XmlSerializer^ myXmlSerializer = gcnew XmlSerializer(
         Student::typeid, myXmlAttributeOverrides );
      return myXmlSerializer;
   }
public void SerializeOrder(String fileName)
{
    // Create an XmlSerializer instance using the method below.
    XmlSerializer myXmlSerializer = CreateOverrider();
    // Create the object, and set its name property.
    Student myStudent = new Student();
    myStudent.name = "Student class1";
    // Serialize the class, and close the TextWriter.
    TextWriter writer = new StreamWriter(fileName);
    myXmlSerializer.Serialize(writer, myStudent);
    writer.Close();
} //SerializeOrder

// Return an XmlSerializer to override the root serialization.
public XmlSerializer CreateOverrider()
{
    // Create an XmlAttributes to override the default root element.
    XmlAttributes myXmlAttributes = new XmlAttributes();
    // Create an XmlRootAttribute and set its element name and namespace.
    XmlRootAttribute myXmlRootAttribute = new XmlRootAttribute();
    myXmlRootAttribute.set_ElementName("OverriddenRootElementName");
    myXmlRootAttribute.set_Namespace("http://www.microsoft.com");
    // Set the XmlRoot property to the XmlRoot object.
    myXmlAttributes.set_XmlRoot(myXmlRootAttribute);
    XmlAttributeOverrides myXmlAttributeOverrides =
        new XmlAttributeOverrides();

    /* Add the XmlAttributes object to the 
       XmlAttributeOverrides object. 
     */
    myXmlAttributeOverrides.Add(Student.class.ToType(), myXmlAttributes);
    // Create the Serializer, and return it.
    XmlSerializer myXmlSerializer = new XmlSerializer(
        Student.class.ToType(), myXmlAttributeOverrides);
    return myXmlSerializer;
} //CreateOverrider
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlRootAttribute クラス
XmlRootAttribute メンバ
System.Xml.Serialization 名前空間



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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2024 GRAS Group, Inc.RSS