【发布时间】:2010-03-30 01:43:13
【问题描述】:
我在使用 Linq to XML 解析以下 XML 时遇到问题。我正在做的是让元素检查它是否是我想要的,然后转到下一个。我很确定它与 xmlns 有关,但我需要这段代码才能同时处理这种风格和普通风格的 RSS 提要(没有 xmlns)。有什么想法吗?
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/">
<channel rdf:about="http://someurl.com">
<title>sometitle</title>
XElement currentLocation = startElementParameter;
foreach (string x in ("channel\\Title").Split('\\'))
{
if (condition1 == false)
{
continue;
}
else if (condition2 == false)
{
break;
}
else
{
// This is returning null.
currentLocation = currentLocation.Element(x);
}
}
谢谢!
编辑:XML 粘贴不正确。
【问题讨论】: