簡體   English   中英

Java Xpath排除xml中的子級

[英]Java Xpath to exclude child in xml

我的xml文件如下

<table id="553" name="Schedule Master">
<property name="dataSet">Schedule_Master</property>
                        <list-property name="boundDataColumns">
                            <structure>
                                <property name="name">SCHD_ID</property>
                                <expression name="expression">dataSetRow["SCHD_ID"]</expression>
                                <property name="dataType">decimal</property>
                            </structure>
                        </list-property>
                        <table id="585" name="SegmentInfo_Child">
                                        <property name="dataSet">SegmentInfo_Child</property>
                                                    <list-property name="visibility">
                                                        <structure>
                                                            <property name="format">all</property>
                                                            <expression name="valueExpr">Total.count() &lt; 1</expression>
                                                        </structure>
                                                    </list-property>

                          </table>                  
                        <table id="627" name="EnrollmentInfo_Child">
                                        <property name="dataSet">EnrollmentInfo_Child</property>
                                                    <list-property name="visibility">
                                                        <structure>
                                                            <property name="format">all</property>
                                                            <expression name="valueExpr">Total.count() &lt; 1</expression>
                                                        </structure>
                        </table>                  
</table>

因此,我只想從父表Schedule Schedule獲得信息,這意味着我的xml應該如下所示。

    <table id="553" name="Schedule Master">
    <property name="dataSet">Schedule_Master</property>
                            <list-property name="boundDataColumns">
                                <structure>
                                    <property name="name">SCHD_ID</property>
                                    <expression name="expression">dataSetRow["SCHD_ID"]</expression>
                                    <property name="dataType">decimal</property>
                                </structure>
                            </list-property>
</table>

所以我該如何使用Xpath表達式實現這一點。 我曾嘗試過以下表達式,但顯然它們沒有幫助

1) "//cell/table[1]"  
2) "//table[(descendant::table)]"

提前致謝

如果只想從外部表中提取數據(例如property文本值):

//property[count(ancestor::table) = 1]/text()

這將不匹配內部表的property節點,因為它們有兩個table祖先,因此count(ancestor::table) = 1謂詞將為其返回false

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM