我有一个像这样的 XML 文件:
\n\n我想获取所有标签 a:entry
\n\n<?xml version="1.0" encoding="utf-8"?>\n<a:feed xmlns:a="http://www.w3.org/2005/Atom" xmlns:os="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://schemas.zune.net/catalog/apps/2008/02">\n <a:link rel="next" type="application/atom+xml" href="/v8/catalog/apps?q=facebook&startIndex=50&chunkSize=50&pagingToken=50%7c50&os=8.0.10512.0&cc=US&oc=&lang=vi-VN&hw=469838850&dm=Virtual&oemId=NOKIA&moId=" />\n <a:link rel="self" type="application/atom+xml" href="/v8/catalog/apps?q=facebook&chunkSize=50&os=8.0.10512.0&cc=US&oc=&lang=vi-VN&hw=469838850&dm=Virtual&oemId=NOKIA&moId=" />\n <os:startIndex>0</os:startIndex>\n <os:totalResults>51</os:totalResults>\n <os:itemsPerPage>50</os:itemsPerPage>\n <a:updated>2013-11-01T08:30:11.711450Z</a:updated>\n <a:title type="text">List Of Items</a:title>\n <a:id>tag:catalog.zune.net,2013-11-01:/apps</a:id>\n <pagingToken>50|50</pagingToken>\n <impressionId>cd11c7b0116143dcb4c99f15b72ebbc4</impressionId>\n <a:entry>\n <a:updated>2013-11-01T08:30:11.711450Z</a:updated>\n <a:title type="text">Facebook</a:title>\n <a:id>urn:uuid:82a23635-5bd9-df11-a844-00237de2db9e</a:id>\n <isHardwareCompatible>true</isHardwareCompatible>\n <sortTitle>Facebook</sortTitle>\n <releaseDate>2010-10-19T13:07:17.103000Z</releaseDate>\n <version>5.1.2.0</version>\n <averageUserRating>5.963479</averageUserRating>\n <userRatingCount>42825</userRatingCount>\n <image>\n <id>urn:uuid:f8b42bcd-45c3-4ea5-9c9e-a108ac33cd6e</id>\n </image>\n <hasLiveTile>true</hasLiveTile>\n <categories>\n <category>\n <id>windowsphone.Social</id>\n <title>ma\xcc\xa3ng xa\xcc\x83 h\xc3\xb4\xcc\xa3i</title>\n <isRoot>True</isRoot>\n </category>\n </categories>\n <tags>\n <tag>Independent</tag>\n <tag>LockScreen_Background</tag>\n <tag>LockScreen_Notification_IconCount</tag>\n <tag>LockScreen_Notification_TextField</tag>\n <tag>phone.protocol.fb</tag>\n </tags>\n <offers>\n <offer>\n <offerId>urn:uuid:5c6b4028-74c5-4648-a71e-2ca413a5d2fd</offerId>\n <mediaInstanceId>urn:uuid:64051c69-fb7b-4972-ad42-1dbb2e626a2c</mediaInstanceId>\n <clientTypes>\n <clientType>WindowsPhone80</clientType>\n <clientType>WindowsPhone81</clientType>\n </clientTypes>\n <paymentTypes>\n <paymentType>Credit Card</paymentType>\n <paymentType>Mobile Operator</paymentType>\n </paymentTypes>\n <store>ZEST</store>\n …Run Code Online (Sandbox Code Playgroud) 我在编辑后将字符串解析为XDocument时出现此错误并保存.但任何人都可以帮我找到错误位置 - 第1行,第10475位.我怎么能得到那个位置?
System.Xml.XmlException:意外的XML声明.XML声明必须是文档中的第一个节点,并且不允许在其前面显示空白字符.第1行,第10475位.
if (storage.FileExists("APPSDATA.xml"))
{
var reader = new StreamReader(new IsolatedStorageFileStream("APPSDATA.xml", FileMode.Open, storage));
string xml = reader.ReadToEnd();
var xdoc = XDocument.Parse(xml);//error here
reader.Close();
Run Code Online (Sandbox Code Playgroud)
XML很大,这是jus的一部分
<?xml version="1.0" encoding="UTF-8"?>
<Ungdungs>
<Ungdung>
<Name>HERE City Lens</Name>
<Id>b0a0ac22-cf9e-45ba-8120-815450e2fd71</Id>
<Path>/Icon/herecitylens.png</Path>
<Version>1.0.0.0</Version>
<Category>HERE</Category>
<Date>Uknown</Date>
</Ungdung>
<Ungdung>
<Name>HERE Transit</Name>
<Id>adfdad16-b54a-4ec3-b11e-66bd691be4e6</Id>
<Path>/Icon/heretransit.png</Path>
<Version>1.0.0.0</Version>
<Category>HERE</Category>
<Date>Uknown</Date>
</Ungdung>
Run Code Online (Sandbox Code Playgroud)