Jaxen /text() not working
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?
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]
精彩评论