我有以下 XML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<feed xml:base="http://x.table.core.windows.net/"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns="http://www.w3.org/2005/Atom">
<title type="text">TestContents</title>
<updated />
<link rel="self" title="TestContents" href="TestContents" />
<entry>
<title type="text" />
<updated />
<author>
<name />
</author>
<link rel="edit" />
<content type="application/xml">
<m:properties>
<d:Title>ssq</d:Title>
<d:Type>1</d:Type>
</m:properties>
</content>
</entry>
<entry>
<title type="text" />
<updated />
<author>
<name />
</author>
<link rel="edit" />
<content type="application/xml">
<m:properties>
<d:Title>yy</d:Title>
<d:Type>1</d:Type>
</m:properties>
</content>
</entry>
<entry>
<title type="text" />
<updated />
<author>
<name />
</author>
<link rel="edit" />
<content type="application/xml">
<m:properties>
<d:Title>xx</d:Title>
<d:Type>1</d:Type>
</m:properties>
</content>
</entry>
</feed>
我想访问的值<d:Title>yy</d:Title>
这是 Darin 向我建议的代码:
static void Main(string[] args) {
XNamespace d = "http://schemas.microsoft.com/ado/2007/08/dataservices";
using (var reader = XmlReader.Create(@"c:\data\contents2.xml"))
{
var feed = SyndicationFeed.Load(reader);
foreach (var item in feed.Items)
{
var content = item.Content as XmlSyndicationContent;
if (content != null)
{
var value = content.ReadContent<XElement>();
var text = value.Element(d + "Title");
Console.WriteLine(text.Value);
}
}
Console.ReadLine();
}
}
但是当我运行它时,它只会给我一个错误
Error in line 5 position 3. An error was encountered when parsing a DateTime value in the XML.