我在这个xpath表达式中的where子句不起作用并且总是返回0.我无法弄清楚出了什么问题。代码在这里。 currentRelationship变量的值是' testentity_relname。';
var entity = doc.SelectNodes(string.Format("//Settings/Entity[RelationshipName={0}]", currentRelationship)).Cast<XmlNode>().ToList();
XML文档看起来像这样;
<Settings>
<AccessRightTypes>
<AccessRightType>WriteAccess</AccessRightType>
<AccessRightType>ShareAccess</AccessRightType>
<AccessRightType>ReadAccess</AccessRightType>
<AccessRightType>NoneAccess</AccessRightType>
<AccessRightType>DeleteAccess</AccessRightType>
<AccessRightType>CreateAccess</AccessRightType>
<AccessRightType>AssignAccess</AccessRightType>
<AccessRightType>AppendToAccess</AccessRightType>
<AccessRightType>AppendAccess</AccessRightType>
</AccessRightTypes>
<Entity>
<RelationshipName>testentity_relname.</RelationshipName>
<AccessRight>ReadAccess</AccessRight>
<AccessRight>WriteAccess</AccessRight>
</Entity>
</Settings>
如果我使用&#34; //设置/实体&#34;的xpath表达式我确实得到了单个Entity节点。但同样,where子句不起作用。并且非常感谢信息。
答案 0 :(得分:2)
看起来你在xpath格式字符串中的参数周围缺少单引号。
var entity = doc.SelectNodes(string.Format("//Settings/Entity[RelationshipName='{0}']", currentRelationship)).Cast<XmlNode>().ToList();