Open sradu opened 10 years ago
hi
can you provide a full sample of xml and xpath you run? You could try xpath with text():
var xml = "<book><title>Harry Potter</title></book>"
var doc = new dom().parseFromString(xml)
var title = select(doc, "//title/text()")[0].data
console.log(title)
I have some precreated xpaths to elements. Would have been great to use different funcs (innerhtml, textcontent).
R.
On Tuesday, December 24, 2013, Yaron Naveh wrote:
hi
can you provide a full sample of xml and xpath you run? You could try xpath with text():
var xml = "
" var doc = new dom().parseFromString(xml) var title = select(doc, "//title/text()")[0].data console.log(title) Harry Potter — Reply to this email directly or view it on GitHubhttps://github.com/yaronn/xpath.js/issues/4#issuecomment-31176441 .
Since I only wrapped xpath.js as a node module I need to defer to the original author. @heycam - what does it take to achieve this?
If you have some existing XPath expressions that you are happy to change, but you don't want to change the code around them too much, you could wrap them with a function call for a custom function that would get .textContent
from the result. There's no easy way though to change the evaluate
function to do this automatically though.
@sradu The SelectNodes
wrapper function returns an array of DOMNodes. If you want to access their .innerText
or .textContent
property, you can just go ahead and do so:
var select = require('xpath.js'),
dom = require('xmldom').DOMParser
var xml = "<book><title>Harry Potter</title></book>" ;
var doc = new dom().parseFromString(xml);
var nodes = select(doc, "//title") ;
console.log(nodes[0].textContent);
Currently I get a result like < span >my_div< /span >. Would it be possible to run .innerText or .textContent on the object so I get only the text?