简体   繁体   中英

Java Xpath to exclude child in xml

My xml file is like below

<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>

So I want information only from my parent table that is Schedule Master , which means my xml should look like below.

    <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>

so how can I achieve this using Xpath expression . I had tried below expressions , but obviously they didn't helped

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

Thanks in Advance

If you want to extract data (for instance property text value) from outer table only:

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

This won't match property nodes of inner tables as they have two table ancestors, so count(ancestor::table) = 1 predicate will return false for them

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM