OK. Now there's the question: two uses of the same function with
different path:
var pwd = myPath(xmldoc, "/utenti/utente[@username='mariano']/
password");
var usr = myPath(xmldoc, "/utenti/utente[@id='1']/@username");

First case print NULL, second correctly print MARIANO. Why the first
path return a null value? Both two functions works properly in xPath
Explorer. Thank you all...

The first XPath expression selects an element node ('password') and in
the DOM model the nodeValue of elements nodes is defined to be null. You
need the textContent (W3C DOM Level 3) property or the text (MSXML DOM)
property to access the text content of an element. Or you need to access
the firstChild.nodeValue as in the case of your 'password' element that
child is a text node and text nodes have nodeValue as their contents.

Most of the identifiers here are not well-chosen. myPath() is
not supposed to return a path but a string value, xmlURL does
not designate a URL but an XML document object reference.
I recommend renaming.
> var displayText;
> if (window.XMLHttpRequest) { // mozilla

Martin Honnen wrote:
> [...]
> The first XPath expression selects an element node ('password') and in
> the DOM model the nodeValue of elements nodes is defined to be null. You
> need the textContent (W3C DOM Level 3) property or the text (MSXML DOM)
> property to access the text content of an element. Or you need to access
> the firstChild.nodeValue as in the case of your 'password' element that
> child is a text node and text nodes have nodeValue as their contents.

In this case firstChild.nodeValue may suffice, but not in the general case
as the text content of an element node may consists of several text nodes.
textContent and its equivalent are indeed the best choices here; the safest
would be iterating through the child nodes of the element node.

isMethod() returns `true' if `o' evaluates to `true' (`o' is a reference to
an object reference or something convertible to an object reference), if
typeof o[p] yields something that contains (case-insensitive match) the
word "function" or the word "object" (indicating that o[p] is something
callable), and if o[p] evaluates to `true' (making sure that it does not
yield `null', because `typeof null == "object"'). Otherwise, it returns
`false'.

Please leave in the attribution line Google includes automatically in order
to show the authorship of quoted material.

On 13 Gen, 19:44, Thomas 'PointedEars' Lahn <>
wrote:
> Martin Honnen wrote:
> > [...]
> > The first XPath expression selects an element node ('password') and in
> > the DOM model the nodeValue of elements nodes is defined to be null. You
> > need the textContent (W3C DOM Level 3) property or the text (MSXML DOM)
> > property to access the text content of an element. Or you need to access
> > the firstChild.nodeValue as in the case of your 'password' element that
> > child is a text node and text nodes have nodeValue as their contents.
>
> In this case firstChild.nodeValue may suffice, but not in the general case
> as the text content of an element node may consists of several text nodes.
> textContent and its equivalent are indeed the best choices here; the safest
> would be iterating through the child nodes of the element node.
>
> PointedEars

I'm not so experted in javascript, i've started few days ago to
learning it. How could modify myPath() function to suite my necessity?

Mariano wrote:
> [...] Thomas 'PointedEars' Lahn [...] wrote:
>> Martin Honnen wrote:
>>> [...]
>>> The first XPath expression selects an element node ('password') and in
>>> the DOM model the nodeValue of elements nodes is defined to be null. You
>>> need the textContent (W3C DOM Level 3) property or the text (MSXML DOM)
>>> property to access the text content of an element. Or you need to access
>>> the firstChild.nodeValue as in the case of your 'password' element that
>>> child is a text node and text nodes have nodeValue as their contents.
>> In this case firstChild.nodeValue may suffice, but not in the general case
>> as the text content of an element node may consists of several text nodes.
>> textContent and its equivalent are indeed the best choices here; the safest
>> would be iterating through the child nodes of the element node.
>> [...]

http://jibbering.com/faq/
> I'm not so experted in javascript, i've started few days ago to
> learning it. How could modify myPath() function to suite my necessity?

Replace `nodeValue' with `textContent' in the Document::evaluate() branch
and `nodeValue' with `text' in the XMLDOMDocument::selectSingleNode() branch.

Have you even written the existing code yourself, or is this all just
copy-and-pray? Because from your question it appears you don't know
what you are doing in the first place.

PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!