【发布时间】:2019-10-22 12:28:27
【问题描述】:
我有一个 xml 文件,需要使用 C# 从二级子节点中提取 InnerXML。下面是我的 XML 的 sn-p。
<joblisting:department>Supply</joblisting:department>
<guid isPermaLink="true">https://www.governmentjobs.com/careers/ocso/Jobs/2594527</guid>
<joblisting:categories>
<joblisting:category xmlns:joblisting="http://www.neogov.com/namespaces/JobListing" xmlns:atom="http://www.w3.org/2005/Atom">
<CategoryCode>ClericalDataEntry</CategoryCode>
<Category>Clerical & Data Entry</Category>
</joblisting:category>
</joblisting:categories>
我需要获取 Category 元素的值。
我尝试使用这个 C# 代码:
XmlNode t = rssNode.LastChild;
if (t.HasChildNodes)
{
for (int i = 0; i < t.ChildNodes.Count; i++)
{
string xcategory = (t.ChildNodes[i].InnerXml);
string category = "<category>" + xcategory + "</category>";
sb.AppendLine(category);
}
}
但它将整个子树返回为
<category>
<CategoryCode>ClericalDataEntry</CategoryCode>
<Category>Clerical & Data Entry</Category>
</category
我只想得到 Category 元素的值
我怎样才能只深入到那个元素?
【问题讨论】:
标签: c# xml xml-parsing