0
        string json = "{"Animal":{"id":"123","verified":true}}"

        XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(json);

        returnXml = doc.ToString();

Why does "ReturnXml" return the following text "System.Xml.XmlDocument" and not the XML output in string format?


http://json.codeplex.com/

2 Answers 2

5

To print XML, you need to use InnerXml

doc.InnerXml;
0
1

The ToString method of XmlDocument is not set to output a pretty version of the xml contained therein.

You're best bet may be to just convert that XmlDocument to an XDocument, since that supports a ToString method that outputs actual XML:

XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(json);
XDocument linqXML = XDocument.Load(new XmlNodeReader(doc)); 
returnXML = linqXML.ToString();
2
  • how do I fix it so it outputs xml string? Commented Dec 4, 2011 at 5:02
  • You'll have to do it yourself. check this out stackoverflow.com/questions/203528/… Commented Dec 4, 2011 at 5:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.