Infopath生成的XML文件如下

<Table1>
    <a></a>
    <b></b>
        <c>
             <c1>1</c1>
             <c2>书</c2>
             <c3>好</c3>
        </c>
        <c>
             <c1>2</c1>
             <c2>书</c2>      
             <c3></c3>
        </c>
         <c>
             <c1>3</c1>
             <c2>书</c2>
             <c3>好</c3>
        </c>
        <c>
             <c1>4</c1>
             <c2>4</c2>
             <c3>4</c3>         
        </c>
</Table1>

我想取得所有 c2 = '书' 的 c1的值,网上搜了好半天都没有类似的例子,只好自己根据Infopath模板中的XSL中的Xpath来琢磨

如下是可行的方法:

IXMLDOMNodeList nodelist = thisXDocument.DOM.SelectNodes("//Table1/b/c/c1[../c2 = '书']");
或者
IXMLDOMNodeList nodelist = thisXDocument.DOM.SelectNodes("//Table1/b/c/c1[../c2 = \"书\"]");

如果想取得 c2 ='书' 并且 c3 = '好'的c1值:

IXMLDOMNodeList nodelist = thisXDocument.DOM.SelectNodes("//Table1/b/c/c1[../c2 = '书' and ../c3 = '好']");
或者
IXMLDOMNodeList nodelist = thisXDocument.DOM.SelectNodes("//Table1/b/c/c1[../c2 = \"书\" and ../c3 = '好
posted on 2007-06-01 11:53  Dragon-China  阅读(652)  评论(0编辑  收藏  举报