Home > Blockchain >  XML : xPath - How can I Select all name nodes except empty nodes
XML : xPath - How can I Select all name nodes except empty nodes

Time:10-10

XML : xPath - How can I Select all name nodes except empty nodes. There is a xml file.

/* XML : xPath - How can I Select all name nodes except empty nodes.*/

<name></name> //empty node

<foodlist>
        <fooditem>
                <name>Pizza</name>
                <cost>10€</cost>
        </fooditem>
        
        <fooditem>
                <name></name>
                <cost>5€</cost>
        </fooditem>
            
        <fooditem>
                <name>Burger</name>
                <cost></cost>
        </fooditem>
            
        <fooditem>
                <name>Cream</name>
                <cost></cost>
        </fooditem>
</foodlist>

CodePudding user response:

//name[text()]

This will select all name elements, and then filter them to include only those which contain a text node.

CodePudding user response:

//fooditem[name != '']/name

will give you all none empty food names, you don't have to filter the empty ones

  • Related