I have a web service that returns an xml string as results. The return string is in this format:
<ReturnValue>
<ErrorNumber>0
</ErrorNumber>
<Message>my message</Message>
</ReturnValue>
The data that I want to insert into the “message” tag is a serialized version of a custom object. The serialized format of that object contains xml and namespace declarations post serialization. When that gets thrown into the “message” tag of my return xml string, XmlSpy says that it’s not well-formed. How should I get rid of the namespace declarations, or is there a different way to imbed a serialized object into an xml string?
Just make sure that your
<Message>XML is encoded so that<,>,", and&show up as<,>,"and&, respectively.There are few built-in ways to encode the characters:
XmlTextWriterto do the work for youCDATAto wrap your XMLAlso, this is probably a duplicate of: