Serialisation avec CDATA => Cannot Serialize member
Bonjour,
J'ai un petit problème de sérialisation mais je bloque depuis 2j dessus :
J'ai une classe Values qui à un code (XmlAttribute) et une value (XmlText).
Et j'aimerais obtenir dans mon XML :
Code:
<Values code=\"12390\"><![CDATA[Static]]></Values> => où <![CDATA[Static]] est ma value.
au lieu de:
Code:
1 2 3 4 5
| <Values code=\"12390\"><value><![CDATA[Static]]></value></Values> => Je ne veux pas les balises "value"
ou
<Values code=\"12390\">Static</value></Values> => Il manque le CDATA |
Mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public class Values
{
public Values()
{}
[System.Xml.Serialization.XmlAttributeAttribute()]
public long code { get; set; }
private CDATA _val;
//[System.Xml.Serialization.XmlTextAttribute()]
[XmlText(typeof(CDATA))]
public CDATA value
{
get { return _val; }
set { _val = value; }
}
} |
et ma classe CDATA (prise sur internet) :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#region CDATA
public class CDATA : IXmlSerializable
{
private string text;
public CDATA()
{ }
public CDATA(string text)
{
this.text = text;
}
public string Text
{
get { return text; }
}
XmlSchema IXmlSerializable.GetSchema()
{
return null;
}
void IXmlSerializable.ReadXml(XmlReader reader)
{
this.text = reader.ReadString();
reader.Read();
}
void IXmlSerializable.WriteXml(XmlWriter writer)
{
writer.WriteCData(this.text);
}
public override string ToString()
{
return this.text;
}
}
#endregion |
Lorsque je sérialize (BDD vers XML) j'obtiens :
{"Cannot serialize member 'value' of type namespace.CDATA. XmlAttribute/XmlText cannot be used to encode types implementing IXmlSerializable."}
Je sèche donc si quelqu'un à une idée !
Merci beaucoup d'avance