The next class (of an xml) has several attributes and contains text.
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "xxx")]
public partial class consultaSelect : EntityBase<consultaSelect>
{
private string scriptField;
[System.Xml.Serialization.XmlAttributeAttribute()]
public string script
{
get
{
return this.scriptField;
}
set
{
if ((this.scriptField != null))
{
if ((scriptField.Equals(value) != true))
{
this.scriptField = value;
this.OnPropertyChanged("script");
}
}
else
{
this.scriptField = value;
this.OnPropertyChanged("script");
}
}
}
private string valueField;
[System.Xml.Serialization.XmlTextAttribute()]
public string Value
{
get
{
return this.valueField;
}
set
{
if ((this.valueField != null))
{
if ((valueField.Equals(value) != true))
{
this.valueField = value;
this.OnPropertyChanged("Value");
}
}
else
{
this.valueField = value;
this.OnPropertyChanged("Value");
}
}
}
}
The problem is with value. I want it to be a CDATA. However, when writing the get as follows:
get
{
XmlDocument doc = new XmlDocument();
return doc.CreateCDataSection(valueField);
}
this in theory returns the value as CDATA, but forces me to decorate it with a [XmlElement("CDataElement")]
tag that is not what I want, since I want it to be part of the original. When I decorate it in that way, it generates one more element in the final XML:
<select script="pepe">
<CDataElement><![CDATA[SELECT * FROM Users WHERE UserId > 10]]></CDataElement>
</select>
and what I want is:
<select script="pepe">
<![CDATA[SELECT * FROM Users WHERE UserId > 10]]>
</select>
So the problem is, should I decorate it in another way, or am I totally wrong and I have to do it in a different way?