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
  • 3,029
  • 5
  • 34
  • 43
001
  • 62,807
  • 94
  • 230
  • 350

2 Answers2

5

To print XML, you need to use InnerXml

doc.InnerXml;
Siva Charan
  • 17,940
  • 9
  • 60
  • 95
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
  • 82,527
  • 56
  • 270
  • 393
  • 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