基于xpath谓词的组节点

时间:2013-01-09 07:30:23

标签: c# xpath

我有像

这样的xpath字符串
/root/parent/child
/root/parent/child[1]
/root/parent/child[2]

在c#代码中,我正在检查XmlDocument中是否存在xpath,并像这样克隆它

//Get the parent node of the node to be cloned
XmlNode NodeTobeCloned = xmlDoc.SelectSingleNode(oRow[0].ToString());
XmlNode DuplicateNode = NodeTobeCloned.CloneNode(true);
DuplicateNode.InnerText = sValue;
//Insert the node after the last child of a commoon parent
NodeTobeCloned.ParentNode.AppendChild(DuplicateNode);

我得到了像

这样的结果
<root>
<parent>
<child/>
<child/>
<child/>
</parent>
</root>

我想要一个像

这样的结果
<root>
<parent>
<child/>
</parent>
<parent>
<child/> -- [1] -predicates elements
</parent>
<parent>
<child/> -- [2] -predicates elements
</parent>
</root>

如何使用c#附加到xmldocument 谢谢

0 个答案:

没有答案