1
votes

Using XPath, what is a good command to select all nodes in a document that contain information...

 //text() 

selects all the text, but no tags with it, and I get major gaps

  //comment() 

selects the comment section

any ideas would be great

**EDIT for formatting purposes **

I have an XML file which consists of places in the world. so its broken down kind of like this

     <Place id="USA">
      <name>USA</name>
      <econ>
          <crops>corn</crops>
          <travel></travel>
       </econ>
     </place>

This is a very crude example but as you can see travel does not have any text attached to it, nor does place, or econ. I need a xpath statement that would display something like this given the above code

      Name=USA
      Crops=Corn

skipping place, econ, and travel because it does not contain text.

1
Can you elaborate "information" in your question? - Kirill Polishchuk
I have an XML file which consists of places in the world. so its broken down kind of like this <Place id="USA"> <name>USA</name> <econ> <crops>corn</crops> <travel></travel> This is a very crude example but as you can see travel does not have any text attached to it, nor does place, or econ. I need a xpath statement that would display something like this given the above code Name=USA Crops=Corn skipping place, econ, and travel because it does not contain text. - Jeremy
see above for proper look to xml code.... - Jeremy

1 Answers

0
votes

Try this XPath:

//*[normalize-space(text())]

In your case it will return two nodes: name and crops