0

How can I display XML output on ASP.NET page with XML tags?

XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(jsonOutput, "root");
Console.WriteLine(doc.OuterXml);

I would like to get results on my page like this:

<root>
    <id>108013515952807</id>
    <posts>
        <data>
            <message>This...Game... http://www.youtube.com/watch?v=l8Xsex0pqXY</message>
            <id>108013515952807_470604423027046</id>
            <created_time>2013-05-15T20:02:31+0000</created_time>
        </data>
        <data>
            <message>Streaming in a few minutes! http://www.youtube.com/watch?v=IYnHDT6V82k</message>
            <id>108013515952807_470538076367014</id>
            <created_time>2013-05-15T16:46:36+0000</created_time>
        </data>
    </posts>
</root>

I tried this but I get no XML tags like in example above.

Response.Write("<BR>" + doc.OuterXml);
Carsten
  • 11,287
  • 7
  • 39
  • 62
lukso
  • 589
  • 5
  • 13
  • 31

2 Answers2

1

Try

XElement.Parse(request.OuterXml).ToString()

If you want prettified XML string,

refer to: What is the simplest way to get indented XML with line breaks from XmlDocument?

Community
  • 1
  • 1
drhanlau
  • 2,517
  • 2
  • 24
  • 42
1

If you just put XML onto a webpage, the browser thinks it might be HTML and "renders" it, which is why you can't see the tags. You need to encode the XML

You can use the method

Response.Write(Server.HtmlEncode(doc.OuterXml));

Robin Day
  • 100,552
  • 23
  • 116
  • 167