English 中文(简体)
如何在 xpath 中选择所有节点?
原标题:how to select in xpath all nodes except the nodes under a table node that contains a li node?

我有很多表格,我想从这些表格中选择所有的节点, 除了那些至少含有 li 节点的表格。

示例:

<table>
<tr><td>all these nodes should match</td></tr>
</table>

<table>
<tr><td><ul><li>all these nodes including table should NOT match</li></ul></td></tr>
</table>

<table>
<tr><td><div>all these nodes should match</div></td></tr>
</table>
最佳回答

XPATH:

/root/table[not(descendant::li)]

XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <table>
        <tr>
            <td>all these nodes should match</td>
        </tr>
    </table>
    <table>
        <tr>
            <td>
                <ul>
                    <li>all these nodes including table should NOT match</li>
                </ul>
            </td>
        </tr>
    </table>
    <table>
        <tr>
            <td>
                <div>all these nodes should match</div>
            </td>
        </tr>
    </table>
</root>
问题回答

< streng> 尝试此

//table[count(.//li) eq 0]




相关问题
VTD XML inner XPath Expressions

I have a xml file for example like this <root> <test> <bla>test1</bla> </test> <test> <bla>test2</bla> </test> <test> </test&...

C# XML adding/copying

With the following XML I am trying to copy and add to another XML but I haven t used the C# XML document objects before. So here is the XML <config> <configXML> <Connections&...

Filter SQL queries on the XML column using XPath/XQuery

I m having a table with one XML column. I d like to filter out the rows where a specific attribute in the XML match a string, essentially doing a WHERE or HAVING. The table looks something like this ...

Python XPath Result displaying only []

Hey I have just started to use Python recently and I want to use it with a bit of xPath, the thing is when I print the result of the query I only get [] and I don t know why =S import libxml2, ...

热门标签