It's not a secret anymore!*
The moose likes XML and Related Technologies and the fly likes Selecting text without a node with XPath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Selecting text without a node with XPath" Watch "Selecting text without a node with XPath" New topic
Author

Selecting text without a node with XPath

Tim Patton
Greenhorn

Joined: Oct 17, 2006
Posts: 7
I'm trying to figure out how to select some data out of HTML that looks like this:

<p>
<b>aaaa</b>
<i>bbbbb</i>
cccccc
</p>

Getting 'aaaa' and 'bbbb' are easy, but how to I select 'cccc' independent of the others? Somehow I want to say "grab all the text after the close of <i> up to </p>" I can't figure out how to get this sort of "free text" out with xpath.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
Well, that text is in a node - a TEXT_NODE - so if you get the xpath expression to return a NODESET (same as Java's NodeList) for the <p> Element children, you can iterate through it till you find the Node with type TEXT_NODE you can take the value of that node.

Bill
Tim Patton
Greenhorn

Joined: Oct 17, 2006
Posts: 7
I actually foigured it out, the Xpath to use would be something like:

//p/text()

If there is more than one block of text this also works:

//p/text()[1]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Selecting text without a node with XPath