Search the web
Sign In
New User? Sign Up
tdom · tDOM - fast DOM / XPath for Tcl in C
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
selectNode error   Message List  
Reply | Forward Message #1611 of 1984 |
Re: [tdom] selectNode error


On 24 May, Kevin Partin wrote:
> Given an XML document with the following line in it
>
> <library>test</library>
>
> shouldn't the following command return the text node containing the
> value "test"
>
> % set node [$root selectNode library/text()=\"test\"]

No.

> Instead, the command returns the value 1, which I interpret to mean that
> the node was found.

The return value 1 is correct. An XPath expression doesn't necessary
return always a node set.

Your XPath expression is a boolean expression. You ask the XPath
engine, if a certain node set (your /library/text()) is equal (your =)
to a literal (your "test"). XPath does automatic 'type conversion'
(see for the detailed rules http://www.w3.org/TR/xpath#booleans) and
returns the result of the boolean expression to you.

If the [expr] way of doing math isn't convoluted enough for your tast,
you could give the selectNodes method a try and you your math with it:

puts [$root selectNodes 2.3*5.4]

If you think, to use tcl for string processing is way too easy for a
real programmer, why not use the selectNodes method:

puts [$root selectNodes concat("foo","bar")]

And so one.

> The following command will return the library
> element itself
>
> % set node [$root selectNode library\[text()=\"test\"\]]
> domNode0x80b6a04
> % $node asXML
> <library>test</library>

That's the right result. If you want the text node itself, as I
suspect (but that smells like you're eventually working to hard), use

set node [$root selectNodes {library/text()[.='test']}]

rolf





Thu May 24, 2007 10:50 pm

rolf@...
Send Email Send Email

Forward
Message #1611 of 1984 |
Expand Messages Author Sort by Date

Given an XML document with the following line in it <library>test</library> shouldn't the following command return the text node containing the value "test" %...
Kevin Partin
Kevin.Partin@...
Send Email
May 24, 2007
8:47 pm

... No. ... The return value 1 is correct. An XPath expression doesn't necessary return always a node set. Your XPath expression is a boolean expression. You...
rolf@...
Send Email
May 24, 2007
10:51 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help