Display XML String to Browser In XML Format
<p>Can someone help me out in the best way to display a raw xml string to a browser in an xml formatted way?</p>

<p>The code i created below does not display anything to the it and gives in error:</p>

<pre><code>  string xml = GetMessageXml(Request.QueryString["ID"].ToString());
            XDocument doc;
            using (StringReader s = new StringReader(xml.Substring(1)))
            {
                doc = XDocument.Load(s);
            }
            Response.ContentType = "text/xml";
            doc.Save(Response.Output);
            Response.Write(doc.ToString());
</code></pre>

<p><strong>Error:<br/></strong>
XML Parsing Error: junk after document element<br/>
'Location:H t t p: localhost/Accounts/EventLogMessageDetails.aspx?id=178'<br/>
Line Number 83, Column 9:'</p>

<p>this is the xml string:</p>

<pre><code>?&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;Order xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;OrderID&gt;00000000-0000-0000-0000-000000000000&lt;/OrderID&gt;
&lt;IsOrderThrough&gt;true&lt;/IsOrderThrough&gt;
&lt;VendorName&gt;le&lt;/VendorName&gt;
&lt;OrderUniqueIdentifier&gt;K03936&lt;/OrderUniqueIdentifier&gt;
&lt;SoldToCustomerID&gt;A786&lt;/SoldToCustomerID&gt;
&lt;ShipToCustomerID&gt;A786&lt;/ShipToCustomerID&gt;
&lt;OrderType&gt;Standard&lt;/OrderType&gt;
&lt;CustomerPurchaseOrderNumber&gt;PO0000336&lt;/CustomerPurchaseOrderNumber&gt;
&lt;ProjectName /&gt;
&lt;EmailAddress&gt;Nair@ecomkva.com&lt;/EmailAddress&gt;
&lt;DeliveryDate&gt;2012-05-29T10:09:55.492696-05:00&lt;/DeliveryDate&gt;
&lt;ShipToAddress&gt;
&lt;AddressID&gt;00075&lt;/AddressID&gt;
&lt;OrganizationName&gt;SEBA-E&lt;/OrganizationName&gt;
&lt;AddressLine1&gt;3700 STATE&lt;/AddressLine1&gt;
&lt;AddressLine2&gt;Elk&lt;/AddressLine2&gt;
&lt;City&gt;LA CROSSE&lt;/City&gt;
&lt;State&gt;WI&lt;/State&gt;
&lt;ZipCode&gt;54601&lt;/ZipCode&gt;
&lt;Country&gt;US&lt;/Country&gt;
&lt;DaytimePhoneNumber&gt;6782260680EXT&lt;/DaytimePhoneNumber&gt;
&lt;/ShipToAddress&gt;
&lt;ShippingMethodName&gt;FEDEX PRIORITY OVERNIGHT&lt;/ShippingMethodName&gt;
&lt;ShippingMethodID&gt;F01&lt;/ShippingMethodID&gt;
&lt;MarketSegment&gt;Commercial&lt;/MarketSegment&gt;
&lt;Comments&gt;Elk^&lt;/Comments&gt;
&lt;LineItems&gt;
&lt;OrderLineItem&gt;
&lt;LineItemID&gt;00000000-0000-0000-0000-000000000000&lt;/LineItemID&gt;
&lt;ProductID&gt;Kbv&lt;/ProductID&gt;
&lt;Quantity&gt;2&lt;/Quantity&gt;
&lt;ListPrice&gt;10.67&lt;/ListPrice&gt;
&lt;PlacedPrice&gt;3.84&lt;/PlacedPrice&gt;
&lt;DeliveryDate&gt;2012-05-29T10:09:56.6957979-05:00&lt;/DeliveryDate&gt;
&lt;ShippingAddress&gt;
&lt;AddressID&gt;Z00138075&lt;/AddressID&gt;
&lt;OrganizationName&gt;moomoo&lt;/OrganizationName&gt;
&lt;AddressLine1&gt;3700 STATE ROAD 16&lt;/AddressLine1&gt;
&lt;AddressLine2&gt;moomoo&lt;/AddressLine2&gt;
&lt;City&gt;LA CROSSE&lt;/City&gt;
&lt;State&gt;WI&lt;/State&gt;
&lt;ZipCode&gt;54601&lt;/ZipCode&gt;
&lt;Country&gt;US&lt;/Country&gt;
&lt;DaytimePhoneNumber&gt;675555550680EXT&lt;/DaytimePhoneNumber&gt;
&lt;/ShippingAddress&gt;
&lt;ShippingMethodID&gt;F01&lt;/ShippingMethodID&gt;
&lt;EmailAddress&gt;IS@Cnj.com&lt;/EmailAddress&gt;
&lt;Comments /&gt;
&lt;SequenceNumber&gt;0&lt;/SequenceNumber&gt;
&lt;/OrderLineItem&gt;
&lt;/LineItems&gt;
&lt;BusinessUnit /&gt;
&lt;FOBPoint&gt;FB2&lt;/FOBPoint&gt;
&lt;Notify&gt;TD&lt;/Notify&gt;
&lt;WorkOrder /&gt;
&lt;SubmittedByUserName&gt;TDAVIS&lt;/SubmittedByUserName&gt;
&lt;SpecialInstructions /&gt;
&lt;/Order&gt;
</code></pre>
