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/

Frank
  • 2,889
  • 5
  • 32
  • 43
001
  • 59,081
  • 87
  • 224
  • 333

2 Answers2

5

To print XML, you need to use InnerXml

doc.InnerXml;
Siva Charan
  • 17,624
  • 9
  • 58
  • 94
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();
Adam Rackis
  • 81,646
  • 52
  • 262
  • 388
  • how do I fix it so it outputs xml string? – 001 Dec 04 '11 at 05:02
  • You'll have to do it yourself. check this out http://stackoverflow.com/questions/203528/what-is-the-simplest-way-to-get-indented-xml-with-line-breaks-from-xmldocument – Adam Rackis Dec 04 '11 at 05:03