I'm having a little trouble with encoding in my C# application.
So, what I'm trying to do is take an xml element and stuff some data inside of it so I can transport that data through a file to another application. However, whenever I go to serialize that element, the xml text inside of the element is encoded. Is there any way to prevent it from being encoded?
So an example of what something I could have is like this:
<element attribute="foo">
<![CDATA[ some data here.... ]]>
</element>
But what it actually outputs is this:
<element attribute="foo">
<![CDATA[ some data here.... ]] >
</element>
Here is my serializer:
XmlDocument doc = new XmlDocument();
StringBuilder xml = new StringBuilder();
XmlSerializer serializer = new XmlSerializer( objToSerialize.GetType() );
XmlWriterSettings settings = new XmlWriterSettings()
{
OmitXmlDeclaration = true,
Indent = true
};
using ( StringWriter writer = new StringWriter( xml ) )
using ( XmlWriter xmlWriter = XmlWriter.Create( writer, settings ) )
{
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add( "", "" ); // Removes the xsd & xsi namespace declarations from the xml
serializer.Serialize( xmlWriter, objToSerialize, ns );
}
return xml.ToString()
How can I prevent this from occurring? Thank you!
No comments:
Post a Comment