我正在尝试从我的 XML 文件中读取一些数据
姓名/姓名/trckid
1)例如从下面粘贴的xml文件中我想读取名称/名称/trckid
例如:trckid = FF7eb01f7-7985-47b1-8f8c-a0e92395d00f2) 以及 Names/Name/Files/file/uri 其中 formatCode="2001"
例如结果字符串:uri=http://cont.catalog.address.xyz.com/e2/ds/9b660964.jpg
这是我的示例 XML 文件
<?xml version="1.0" encoding="utf-8"?>
<Names tracking="trckids" execTime="0" xmlns="urn:schemas-microsoft-com:address:catalog">
<Name xmlns="urn:schemas-microsoft-com:address:catalog" publishState="Published" lcid="1033" options="0" version="65" filterFlags="32687">
<trckid ref="5ofol35" seoMetaData="/xyz/gpscatalog/">FF7eb01f7-7985-47b1-8f8c-a0e92395d00f</trckid>
<providerId>Test0_2286326_304163829</providerId>
<files>
<file formatCode="2001" gpsFileId="9B660964-1626-466C-8359-F036506D8769" height="102" width="136" fileHash="4a4bcceb08b4ccdd16a958e8687c9588">
<uri>http://cont.catalog.address.xyz.com/e2/ds/9b660964-1626-466c-8359-f036506d8769.jpg</uri>
</file>
<file formatCode="2007">
<uri>http://img1.catalog.address.xyz.com/image.aspx?uuid=d7eb01f7-7985-47b1-8f8c-a0e92395d00f&w=136&h=102</uri>
</file>
<file formatCode="2200" gpsFileId="6C34F723-D798-4DA8-AEE4-0442C239D3A0" fileSize="311469" height="180" width="320" sourceFileHash="6ea74770f622e3e0dc9cf5e229c7de7f">
<uri>http://cont.catalog.address.xyz.com/e2/ds/0909a015-4b6a-4574-be63-c2facd527b9f_0.xml</uri>
</file>
</files>
</Name>
<Name xmlns="urn:schemas-microsoft-com:address:catalog" publishState="Published" lcid="1033" options="0" version="65" filterFlags="32687">
<trckid ref="5ofol20" seoMetaData="/xyz/gpscatalog/">FF9eb01f7-7985-47b1-8f8c-a0e92395d00f</trckid>
<providerId>Test1TheLorax_2286326_304163829</providerId>
<files>
<file formatCode="2001" gpsFileId="9B660964-1626-466C-8359-F036506D8769" height="102" width="136" fileHash="4a4bcceb08b4ccdd16a958e8687c9588">
<uri>http://cont.catalog.address.xyz.com/e2/ds/9b660964-1626-466c-8359-f036506d8769.jpg</uri>
</file>
<file formatCode="2007">
<uri>http://img1.catalog.address.xyz.com/image.aspx?uuid=d7eb01f7-7985-47b1-8f8c-a0e92395d00f&w=136&h=102</uri>
</file>
<file formatCode="2200" gpsFileId="6C34F723-D798-4DA8-AEE4-0442C239D3A0" fileSize="311469" height="180" width="320" sourceFileHash="6ea74770f622e3e0dc9cf5e229c7de7f">
<uri>http://cont.catalog.address.xyz.com/e2/ds/0909a015-4b6a-4574-be63-c2facd527b9f_0.xml</uri>
</file>
</files>
</Name>
</Names>
我尝试使用以下给定的代码
XDocument xdoc = XDocument.Parse(xmlstring);
XNamespace ns = xdoc.Root.GetDefaultNamespace(); // "urn:schemas-microsoft-com:msnvideo:catalog";
IEnumerable<XElement> names = xdoc.Descendants(ns + "name");
foreach (XElement name in names)
{
rssFeedItems.Add(new Adressses
{
trackid= Convert.ToString(name.Element(ns + "trackid").Value),
providerID= Convert.ToString(name.Element(ns + "provideid").Value),
imageUri = Convert.ToString(name.Element(ns + "uri").Value)
});
}
Here am able to read first two items ,ie, trackid and providerID ,but not the image uri
我需要读取与 Names/Name/files/file@formatcode[2001]/uri 匹配的 uri
就像是
imageUri = Convert.ToString(name.Element(ns + "Names/Name/files/file@formatcode[2001]/uri").Value)
但这只是行不通。请帮忙