我有以下XML:
<guidance icon="G">
<text newpara="N">
The amount of a firm'scapital
resources maintained for the purposes of <k2:xref revoked="20061231" in_force_from="20050114">
<k2:xrefout revoked="20061231">PRU 9.3.30 R</k2:xrefout>
</k2:xref>
<changed-by in_force_from="20070101">2006/43</changed-by>
</text>
<text in_force_from="20070101" newpara="N">
<k2:xref in_force_from="20070101">
<k2:xrefout xlink:type="simple" xlink:label="SRC527" k2:destElementId="DES60" >MIPRU 4.2.11 R</k2:xrefout>
</k2:xref>
<changed-by in_force_from="20070101">2006/43</changed-by>
</text>
</guidance>
法典:
textNodes = levelNode.SelectNodes("guidance");
string text = textNodes.InnerText;
我收到文本
"公司资本的金额 为PRU 9.3.30 R2006/43MIPRU 4.2.11 R2006/43的目的维护的资源"。
我想要的是,如果文本子节点内有一个撤销的属性,那么文本将不会包含在文本变量中。 因此,文本将在上面的示例中:
"公司资本的金额 为2006/43MIPRU 4.2.11 R目的维持的资源">
你可以这样做
var values = xmlDoc.DocumentElement
.SelectSingleNode("//guidance")
.SelectNodes("//*[not(@revoked)]/text()")
.OfType<XmlNode>()
.Select(n => n.Value.Trim());
string text = string.Concat(values);
命名空间
using System;
using System.Linq;
using System.Xml;