【发布时间】:2012-04-24 22:20:39
【问题描述】:
我正在从 xxx URl 读取 xml,但由于缺少 Root 元素而出现错误。
我读取xml响应的代码如下:
XmlDocument doc = new XmlDocument();
doc.Load("URL from which i am reading xml");
XmlNodeList nodes = doc.GetElementsByTagName("Product");
XmlNode node = null;
foreach (XmlNode n in nodes)
{
}
xml响应如下:
<All_Products>
<Product>
<ProductCode>GFT</ProductCode>
<ProductName>Gift Certificate</ProductName>
<ProductDescriptionShort>Give the perfect gift. </ProductDescriptionShort>
<ProductDescription>Give the perfect gift.</ProductDescription>
<ProductNameShort>Gift Certificate</ProductNameShort>
<FreeShippingItem>Y</FreeShippingItem>
<ProductPrice>55.0000</ProductPrice>
<TaxableProduct>Y</TaxableProduct>
</Product>
</All_Products>
你能告诉我哪里出错了。
【问题讨论】:
-
会不会是没有 XML 声明?
-
您提供的 xml 代码在 LINQPad 下工作(没有错误)。也许您粘贴的 xml 不是被读取的内容?您确定 doc.Load 可以正常工作并加载您提供的内容吗?
-
我检查了你的代码,它在我的最后工作正常,你确定你没有得到空 XML?