tags:

views:

26

answers:

1

I have the html:

<p>
<a href="#">click here</a>
Welcome
</p>

And I just want to retrieve the "Welcome" part using Xpath combined with the Jaxen lib the Xpath I am using is;

//p/text()

Now when I remove the /text() it retrieves;

click here
Welcome

With the /text() added it retrieve null Is there any other way to retrieve everything inside the p tag but excluding any other tags?

+1  A: 

From the XML parser point of view, there are multiple text elements to choose from (Welcome and the whitespace preceding and following it), so it doesn't choose any one. You have a few options, mainly stripping the whitespace before parsing or being more specific about the query, like selecting the second most text element:

//p/text()[2]
Kevin
Thanks for the quick response :-)
MrThys