有人可以帮我在显示在一个XML格式的方式原始XML字符串到浏览器的最佳方法是什么?显示XML字符串到浏览器的XML格式
我下面创建不显示任何内容到它,并在错误给出了代码:
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());
错误:
XML解析错误 :文档元素后的垃圾
“位置:H TTP:本地主机/客户/ EventLogMessageDetails.aspx ID = 178'
行号83,第9列:”?
这是XML字符串:
?<?xml version="1.0" encoding="utf-8"?>
<Order xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<OrderID>00000000-0000-0000-0000-000000000000</OrderID>
<IsOrderThrough>true</IsOrderThrough>
<VendorName>le</VendorName>
<OrderUniqueIdentifier>K03936</OrderUniqueIdentifier>
<SoldToCustomerID>A786</SoldToCustomerID>
<ShipToCustomerID>A786</ShipToCustomerID>
<OrderType>Standard</OrderType>
<CustomerPurchaseOrderNumber>PO0000336</CustomerPurchaseOrderNumber>
<ProjectName />
<EmailAddress>[email protected]</EmailAddress>
<DeliveryDate>2012-05-29T10:09:55.492696-05:00</DeliveryDate>
<ShipToAddress>
<AddressID>00075</AddressID>
<OrganizationName>SEBA-E</OrganizationName>
<AddressLine1>3700 STATE</AddressLine1>
<AddressLine2>Elk</AddressLine2>
<City>LA CROSSE</City>
<State>WI</State>
<ZipCode>54601</ZipCode>
<Country>US</Country>
<DaytimePhoneNumber>6782260680EXT</DaytimePhoneNumber>
</ShipToAddress>
<ShippingMethodName>FEDEX PRIORITY OVERNIGHT</ShippingMethodName>
<ShippingMethodID>F01</ShippingMethodID>
<MarketSegment>Commercial</MarketSegment>
<Comments>Elk^</Comments>
<LineItems>
<OrderLineItem>
<LineItemID>00000000-0000-0000-0000-000000000000</LineItemID>
<ProductID>Kbv</ProductID>
<Quantity>2</Quantity>
<ListPrice>10.67</ListPrice>
<PlacedPrice>3.84</PlacedPrice>
<DeliveryDate>2012-05-29T10:09:56.6957979-05:00</DeliveryDate>
<ShippingAddress>
<AddressID>Z00138075</AddressID>
<OrganizationName>moomoo</OrganizationName>
<AddressLine1>3700 STATE ROAD 16</AddressLine1>
<AddressLine2>moomoo</AddressLine2>
<City>LA CROSSE</City>
<State>WI</State>
<ZipCode>54601</ZipCode>
<Country>US</Country>
<DaytimePhoneNumber>675555550680EXT</DaytimePhoneNumber>
</ShippingAddress>
<ShippingMethodID>F01</ShippingMethodID>
<EmailAddress>[email protected]</EmailAddress>
<Comments />
<SequenceNumber>0</SequenceNumber>
</OrderLineItem>
</LineItems>
<BusinessUnit />
<FOBPoint>FB2</FOBPoint>
<Notify>TD</Notify>
<WorkOrder />
<SubmittedByUserName>TDAVIS</SubmittedByUserName>
<SpecialInstructions />
</Order>
问题在于你得到的XML。它无法解析它。请向我们展示您尝试编写的整个XML。我从错误消息中得出的猜测是,你有两个根元素,即第一个'Order'是第一个元素,那么你之后有另一个'Order'。这不是有效的XML文档。除此之外,你似乎通过使用XDocument的ToString在正确的轨道上。 –
我想你应该参考这个SO后 - http://stackoverflow.com/questions/350314/easiest-way-to-display-xml-on-an-asp-net-page –
为什么不使用LINQ到XML,是什么你想从XML中提取? –