X
Xandor Leahte
Hey there,
I wish to introduce you to a problem that i get working on Javascript
and XPath.
Be r an XMLHttpRequest object; i want to make a request through a
webpage inside my domain (so no security problem); with r i can handle
r.responseText and r.responseXML: sometimes i can't use responseXML
cause of no valid syntax of the document, so I've to use responseText.
So, creating the DOM document like this way:
var doc = new DOMParser().parseFromString(r.responseText, "text/
xml")
Then I can try to evaluate a XPath expression on doc, like:
doc.evaluate(query, doc, null, 0, null)
where query is a valid XPath expression. There's the problem: if I
make a query like "//*[@id='foo']" or "//*" it works perfectly;
otherwise if i make a query like "/html/body" or "/ol/li/a" or
something without wildcard * included, the evaluate function returns
null. I can't understand why if i dont use the wildcard query doesn't
work (see: query works if I try to evaluate it in a "document" contest
like in firebug/js console where my page is the "document" object).
I think it's a problem of parsing request but i dont know ways to do
it; maybe i could use a hidden iframe but it's not so elegant. I wish
to know if you know something about this problem, maybe a problem
about DOM parsing or something like that...
Thanks for all your reply and sorry for my english, I hope you can
forgive me!
Sincerely,
X.
I wish to introduce you to a problem that i get working on Javascript
and XPath.
Be r an XMLHttpRequest object; i want to make a request through a
webpage inside my domain (so no security problem); with r i can handle
r.responseText and r.responseXML: sometimes i can't use responseXML
cause of no valid syntax of the document, so I've to use responseText.
So, creating the DOM document like this way:
var doc = new DOMParser().parseFromString(r.responseText, "text/
xml")
Then I can try to evaluate a XPath expression on doc, like:
doc.evaluate(query, doc, null, 0, null)
where query is a valid XPath expression. There's the problem: if I
make a query like "//*[@id='foo']" or "//*" it works perfectly;
otherwise if i make a query like "/html/body" or "/ol/li/a" or
something without wildcard * included, the evaluate function returns
null. I can't understand why if i dont use the wildcard query doesn't
work (see: query works if I try to evaluate it in a "document" contest
like in firebug/js console where my page is the "document" object).
I think it's a problem of parsing request but i dont know ways to do
it; maybe i could use a hidden iframe but it's not so elegant. I wish
to know if you know something about this problem, maybe a problem
about DOM parsing or something like that...
Thanks for all your reply and sorry for my english, I hope you can
forgive me!
Sincerely,
X.