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

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

XmlAttributes.XmlText プロパティ

XmlSerializer に対してパブリック フィールドまたは読み書き可能パブリック プロパティXML テキストとしてシリアル化するよう指示するオブジェクト取得または設定します

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

Public Property XmlText As
 XmlTextAttribute
Dim instance As XmlAttributes
Dim value As XmlTextAttribute

value = instance.XmlText

instance.XmlText = value
public XmlTextAttribute XmlText { get; set;
 }
public:
property XmlTextAttribute^ XmlText {
    XmlTextAttribute^ get ();
    void set (XmlTextAttribute^ value);
}
/** @property */
public XmlTextAttribute get_XmlText ()

/** @property */
public void set_XmlText (XmlTextAttribute value)
public function get XmlText
 () : XmlTextAttribute

public function set XmlText
 (value : XmlTextAttribute)

プロパティ
パブリック プロパティまたはフィールド既定シリアル化オーバーライドする XmlTextAttribute。

解説解説

既定では、パブリック フィールドまたは読み書き可能パブリック プロパティは、XmlSerializer により XML 要素としてシリアル化されます。ただし、このフィールドまたはプロパティXmlTextAttribute適用すると、強制的にこのフィールドまたプロパティXML テキストとしてシリアル化できます

メモメモ

配列返すフィールドまたはプロパティには、XmlTextAttribute適用できません。

配列返さないフィールドまたはプロパティ既定シリアル化オーバーライドするには、XmlTextAttribute作成し、それを XmlAttributes オブジェクトXmlText プロパティ代入ます。XmlAttributes オブジェクトを XmlAttributeOverrides オブジェクト追加しオーバーライドされるフィールドまたはプロパティを含むオブジェクトの型、およびオーバーライドされるフィールドまたはプロパティの名前を指定します

使用例使用例

Comment という名前のフィールドを含む Group という名前のクラスシリアル化する例を次に示します。この例では、XmlSerializerフィールドシリアル化する既定方法オーバーライドするために、XmlAttributeOverrides および XmlAttributes オブジェクト作成します次にXmlTextAttribute オブジェクト作成して XmlText プロパティ代入し、XmlAttributes オブジェクトを (XML テキストとしてシリアル化されるフィールドの名前で) XmlAttributeOverrides オブジェクト追加します最後にXmlAttributeOverrides オブジェクト使用して XmlSerializer作成します

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


' This is the class that will be serialized.
Public Class Group
    Public GroupName As String
    
    ' This field will be serialized as XML text. 
    Public Comment As String
End Class


Public Class Run
    
    Public Shared Sub Main()
        Dim test As New
 Run()
        test.SerializeObject("OverrideText.xml")
        test.DeserializeObject("OverrideText.xml")
    End Sub

        
    ' Return an XmlSerializer to be used for overriding. 
    Public Function CreateOverrider() As
 XmlSerializer
        ' Create the XmlAttributeOverrides and XmlAttributes objects.
        Dim xOver As New
 XmlAttributeOverrides()
        Dim xAttrs As New
 XmlAttributes()
        
        ' Create an XmlTextAttribute and assign it to the XmlText
        ' property. This instructs the XmlSerializer to treat the
        ' Comment field as XML text. 
        Dim xText As New
 XmlTextAttribute()
        xAttrs.XmlText = xText
        xOver.Add(GetType(Group), "Comment",
 xAttrs)
        
        ' Create the XmlSerializer, and return it.
        Return New XmlSerializer(GetType(Group),
 xOver)
    End Function
    
    
    
    Public Sub SerializeObject(ByVal
 filename As String)
        ' Create an instance of the XmlSerializer class.
        Dim mySerializer As XmlSerializer =
 CreateOverrider()
        ' 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 object properties.
        myGroup.GroupName = ".NET"
        myGroup.Comment = "Great Stuff!"
        ' Serialize the class, and close the TextWriter.
        mySerializer.Serialize(writer, myGroup)
        writer.Close()
    End Sub
    
    
    Public Sub DeserializeObject(ByVal
 filename As String)
        Dim mySerializer As XmlSerializer =
 CreateOverrider()
        Dim fs As New FileStream(filename,
 FileMode.Open)
        Dim myGroup As Group = CType(mySerializer.Deserialize(fs),
 Group)
        Console.WriteLine(myGroup.GroupName)
        Console.WriteLine(myGroup.Comment)
    End Sub
End Class

using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

// This is the class that will be serialized.
public class Group
{
   public string GroupName;

   // This field will be serialized as XML text. 
   public string Comment;
}
 
public class Run
{
   public static void Main()
   {
      Run test = new Run();
      test.SerializeObject("OverrideText.xml");
      test.DeserializeObject("OverrideText.xml");
   }

   // Return an XmlSerializer to be used for overriding. 
   public XmlSerializer CreateOverrider()
   {
      // Create the XmlAttributeOverrides and XmlAttributes objects.
      XmlAttributeOverrides xOver = new XmlAttributeOverrides();
      XmlAttributes xAttrs = new XmlAttributes();

      /* Create an XmlTextAttribute and assign it to the XmlText 
      property. This instructs the XmlSerializer to treat the 
      Comment field as XML text. */      
      XmlTextAttribute xText = new XmlTextAttribute();
      xAttrs.XmlText = xText;
      xOver.Add(typeof(Group), "Comment", xAttrs);

      // Create the XmlSerializer, and return it.
      return new XmlSerializer(typeof(Group),
 xOver);
   }
   
 
   public void SerializeObject(string
 filename)
   {
      // Create an instance of the XmlSerializer class.
      XmlSerializer mySerializer =  CreateOverrider();
      // 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 object properties.
      myGroup.GroupName = ".NET";
      myGroup.Comment = "Great Stuff!";      
      // Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myGroup);
      writer.Close();
   }

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

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

// This is the class that will be serialized.
public ref class Group
{
public:
   String^ GroupName;

   // This field will be serialized as XML text. 
   String^ Comment;
};

// Return an XmlSerializer to be used for overriding. 
XmlSerializer^ CreateOverrider()
{
   // Create the XmlAttributeOverrides and XmlAttributes objects.
   XmlAttributeOverrides^ xOver = gcnew XmlAttributeOverrides;
   XmlAttributes^ xAttrs = gcnew XmlAttributes;

   /* Create an XmlTextAttribute and assign it to the XmlText 
      property. This instructs the XmlSerializer to treat the 
      Comment field as XML text. */
   XmlTextAttribute^ xText = gcnew XmlTextAttribute;
   xAttrs->XmlText = xText;
   xOver->Add( Group::typeid, "Comment", xAttrs );

   // Create the XmlSerializer, and return it.
   return gcnew XmlSerializer( Group::typeid,xOver );
}

void SerializeObject( String^ filename )
{
   // Create an instance of the XmlSerializer class.
   XmlSerializer^ mySerializer = CreateOverrider();

   // 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 object properties.
   myGroup->GroupName = ".NET";
   myGroup->Comment = "Great Stuff!";

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

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

int main()
{
   SerializeObject( "OverrideText.xml" );
   DeserializeObject( "OverrideText.xml" );
}
import System.*;
import System.IO.*;
import System.Xml.*;
import System.Xml.Serialization.*;

// This is the class that will be serialized.
public class Group
{
    public String groupName;
    // This field will be serialized as XML text. 
    public String comment;
} //Group

public class Run
{
    public static void main(String[]
 args)
    {
        Run test = new Run();
        test.SerializeObject("OverrideText.xml");
        test.DeserializeObject("OverrideText.xml");
    } //main

    // Return an XmlSerializer to be used for overriding. 
    public XmlSerializer CreateOverrider()
    {
        // Create the XmlAttributeOverrides and XmlAttributes objects.
        XmlAttributeOverrides xOver = new XmlAttributeOverrides();
        XmlAttributes xAttrs = new XmlAttributes();

        /* Create an XmlTextAttribute and assign it to the XmlText 
           property. This instructs the XmlSerializer to treat the 
           Comment field as XML text. */
        XmlTextAttribute xText = new XmlTextAttribute();
        xAttrs.set_XmlText(xText);
        xOver.Add(Group.class.ToType(), "Comment", xAttrs);

        // Create the XmlSerializer, and return it.
        return new XmlSerializer(Group.class.ToType(),
 xOver);
    } //CreateOverrider

    public void SerializeObject(String fileName)
    {
        // Create an instance of the XmlSerializer class.
        XmlSerializer mySerializer = CreateOverrider();

        // 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 object properties.
        myGroup.groupName = ".NET";
        myGroup.comment = "Great Stuff!";

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

    public void DeserializeObject(String fileName)
    {
        XmlSerializer mySerializer = CreateOverrider();
        FileStream fs = new FileStream(fileName, FileMode.Open);
        Group myGroup = (Group)mySerializer.Deserialize(fs);

        Console.WriteLine(myGroup.groupName);
        Console.WriteLine(myGroup.comment);
    } //DeserializeObject
} //Run
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlAttributes クラス
XmlAttributes メンバ
System.Xml.Serialization 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からXmlAttributes.XmlText プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からXmlAttributes.XmlText プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からXmlAttributes.XmlText プロパティ を検索

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

辞書ショートカット

すべての辞書の索引

「XmlAttributes.XmlText プロパティ」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS