2012-02-09 6 views
0

私は私のオブジェクトの1のC#のシリアル化を使用しています:特定のXMLオブジェクトのシリアル化形式を強制

StringWriter outStream = new StringWriter(); 
    XmlSerializer s = new XmlSerializer(obj.GetType()); 
    XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); 
    s.Serialize(outStream, obj, ns); 
    string xml = outStream.ToString(); 

オブジェクトは次のとおりです。

public class Points 
{ 
    [System.Xml.Serialization.XmlAttribute] 
    public string Type; 
    public double Number; 
} 

Pointsクラスが別のプログラムによって使用されています

<Points Type="Credit">123</Points> 

強制的に任意の属性を使用することができますか?この形式?私はあなたがタイプにXmlAttributeをどうのように、番号]フィールドに[System.Xml.Serialization.XmlText]属性を使用する必要があると思う

おかげ

+1

は、このスレッドを参照してください。/questions/307433/how-to-serialize-to-datetime – twilson

答えて

1

:http://stackoverflow.com:

public class Points 
{ 
    [System.Xml.Serialization.XmlAttribute] 
    public string Type; 
    [System.Xml.Serialization.XmlText] 
    public double Number; 
} 
関連する問題