From: Thomas 'PointedEars' Lahn on
Thomas 'PointedEars' Lahn wrote:

> Suppose your XPath expression does not work, then it is impossible to say
> why that would be so without you providing further details about your
> runtime environment and the document; at best, a test case. I have since
> updated synhl() and '//code[not(contains(concat(" ", @class, " "),
> "donthl"))]' works fine in "Mozilla/5.0 (X11; U; Linux i686; en-US;
> rv:1.9.2.3) Gecko/20100404 Iceweasel/3.6.3 (like Firefox/3.6.3) GTB7.0".

Supplemental: This XPath expression is bogus. Its purpose was to match
`code' elements only when their `class' attribute contained "foo", but only
when it is a word (i.e. a class name), and not in "foobar". So it needs to
be

'//code[not(contains(concat(" ", @class, " "), " donthl "))]'

assuming one would use only spaces as white-space delimiter of a `class'
attribute. Suggestions welcome.


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
From: kelvSYC on
On Jun 7, 6:23 am, Thomas 'PointedEars' Lahn <PointedE...(a)web.de>
wrote:
> kelvSYC wrote:
> > Thomas 'PointedEars' Lahn wrote:
> >> kelvSYC wrote:
> >> > var result = document.evaluate('//div[@class="code"]/code', document,
> >> > null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
>
> >> > if (result) {
> >> > for (var i = 0, len = result.snapshotLength; i < len; i++) {
> >> > // use snapshotItem(i) to get nodes
> >> > var val = result.snapshotItem(i).nodeValue;
> >> > val = val.replace(/<-/gi, "←");
> >> > result.snapshotItem(i).nodeValue = val;
> >> > }
> >> > }
>
> >> > The problem is that, even though I checked that my xpath works, the
> >> > result list is empty for some reason even though I know that it should
> >> > not be empty.  Because of this, I haven't even checked to see that the
> >> > inside code works.  Why is that?
>
> >> The `nodeValue' of an element node is not the content of the element; it
> >> is `null' by definition, and assigning to that property has no effect
> >> then. The element node has a text node as child node, which `nodeValue'
> >> you need to change.  [...]
>
> > Interesting about the inner part.  But I still don't get why the xpath
> > expression "//div[@class="code"]/code" isn't matching anything, even
> > though there is such a thing in my document.  I'm seeing "//div" not
> > matching anything, "//body" not matching anything, even "//html" not
> > matching anything.  I can get "//*[@class="code"]" to match, though.
>
> In your first posting you have said that your XPath expression works, only
> that the element content does not change.  Therefore, I have explained why
> it does not change and how to change it.
>
> But now you are saying the XPath expression does not work in the first
> place.  Something does not add up here.
>
> Suppose your XPath expression does not work, then it is impossible to say
> why that would be so without you providing further details about your
> runtime environment and the document; at best, a test case.  I have since
> updated synhl() and '//code[not(contains(concat(" ", @class, " "),
> "donthl"))]' works fine in "Mozilla/5.0 (X11; U; Linux i686; en-US;
> rv:1.9.2.3) Gecko/20100404 Iceweasel/3.6.3 (like Firefox/3.6.3) GTB7.0".

Sorry. I'm using Safari 5.0 right now. I can't seem to find a place
where you could get the user agent string. Can anyone point out where
I can do so?

To reiterate, XPath expressions where you name specific child nodes
don't appear to work: even "//html" returns no results. However, "//
*" returns nodes, as is "//*[position() = 1]", say. I'm stumped in
that regard.
From: Thomas 'PointedEars' Lahn on
kelvSYC wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Suppose your XPath expression does not work, then it is impossible to say
>> why that would be so without you providing further details about your
>> runtime environment and the document; at best, a test case. I have since
>> updated synhl() and '//code[not(contains(concat(" ", @class, " "),
>> "donthl"))]' works fine in "Mozilla/5.0 (X11; U; Linux i686; en-US;
>> rv:1.9.2.3) Gecko/20100404 Iceweasel/3.6.3 (like Firefox/3.6.3) GTB7.0".
>
> Sorry. I'm using Safari 5.0 right now. I can't seem to find a place
> where you could get the user agent string. Can anyone point out where
> I can do so?

Use the script console to display navigator.userAgent, use web-sniffer.net,
set up a dummy Web server, check your server logs, etc.

> To reiterate, XPath expressions where you name specific child nodes
> don't appear to work: even "//html" returns no results. However, "//
> *" returns nodes, as is "//*[position() = 1]", say. I'm stumped in
> that regard.

To reiterate, you are not providing sufficient information.

If I were to make an educated guess from the available data, the problem
might be that XPath is case-sensitive with regard to element type names;
HTML is not.

Please trim your quotes to the relevant minimum.


PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7(a)news.demon.co.uk> (2004)