我有一个生成XML文档的URL端点,我正在使用此代码尝试将数据放入XML Document对象。
XmlDocument myDoc = new XmlDocument();
myDoc.Load("[my-URL-here-]");
但是我收到以下错误:根级别的数据无效。第1行,位置1
当我使用SAME代码尝试获取此URL https://www.w3schools.com/xml/note.xml(w3schools -sample)时
我没有收到错误
我的URL输出是这个:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<ArrayOfAutoCompleteResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://schemas.datacontract.org/2004/07/mysite.Services">
<AutoCompleteResult>
<BrandName>Trazodone</BrandName>
<Name>Trazodone Hydrichloride</Name>
<ParentId>11403</ParentId>
</AutoCompleteResult>
<AutoCompleteResult>
<BrandName>LysaKare</BrandName>
<Name>Arginine/Lysine</Name>
<ParentId>11403</ParentId>
</AutoCompleteResult>
</ArrayOfAutoCompleteResult>
所以为什么W3schools示例URL起作用而我的却不起作用。
我在您的xml中收到以下错误。System.Xml.XmlException:“ xm”是意外令牌。期待空白。第1行,位置79。在第一个和第二个xmlnsp属性之间必须有一个空格。试试下面的xml。它对我有用。
<ArrayOfAutoCompleteResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/mysite.Services">
<AutoCompleteResult>
<BrandName>Trazodone</BrandName>
<Name>Trazodone Hydrichloride</Name>
<ParentId>11403</ParentId>
</AutoCompleteResult>
<AutoCompleteResult>
<BrandName>LysaKare</BrandName>
<Name>Arginine/Lysine</Name>
<ParentId>11403</ParentId>
</AutoCompleteResult>
</ArrayOfAutoCompleteResult>