For Programmers: Free Programming Magazines  


Home > Archive > Tcl > November 2006 > TclXML confusions (was: How can I ensure that I always have a list?)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author TclXML confusions (was: How can I ensure that I always have a list?)
Cameron Laird

2006-11-25, 7:02 pm

In article <jijl34-ipc.ln1@lairds.us>, I recommended:
>In article <1164440504.571107.104710@h54g2000cwb.googlegroups.com>,
>comp.lang.tcl <phillip.s.powell@gmail.com> wrote:
> .
> .
> .
> .
> .
> .
>Should we recommend a SAX or XQuery approach for this?
>A SAX accumulator used to be canonical for something
>this simple; I haven't worked with Rolf's XPath, but I
>suspect it affords a one-liner that satisfies the
>requirements.


Oh, my; I *do* perceive deficiencies in TclXML documentation.

I know that TclXML has had XPath since 2001. In particular, by 2004,
Steve wrote about selectNodes in 3.0 <URL:
http://talkaboutprogramming.com/gro...ges/253140.html >.
When I run

puts [package require dom]

set xml_image {<?xml version = "1.0" encoding = "UTF-8" ?>
<via id="1" trivia_id="255" question="How much wood would a
woodchuck chuck?" answer_id="1" answer="A lot"
expDate="116494926"></via>
}

set doc [dom::parse $xml_image]
set nodes [$doc selectNodes //via]

on a recent Mac OS, though, I see

3.1
bad method "selectNodes": must be cget, configure, createElement,
createDocumentFragment, createTextNode, createComment,
createCDATASection, createProcessingInstruction, createAttribute,
createEntity, createEntityReference, createDocTypeDecl, importNode,
createElementNS, createAttributeNS, getElementsByTagNameNS,
getElementsById, createEvent, getElementsByTagName, dtd, or schema

So: what's it take to get TclXML to do XPath?
comp.lang.tcl

2006-11-28, 8:04 am


Cameron Laird wrote:
> In article <rtdm34-9pv.ln1@lairds.us>, Cameron Laird <claird@lairds.us> wrote:
>
> The conversation has become rather convoluted, in part because
> of my redirections. I'm going to summarize here a bit of what
> Steve Ball wrote to me and the TclXML mailing list.
>
> "DOM Level 3 has an official method for using XPath with a DOM
> tree, but I haven't had time to implement that yet. . . ."
>
> The TclXML is a bit different from some of the documentation
> available on the Web. Here's my latest version of an XPath-based
> script which makes a list of all attributes of all tags (that's
> the "//@*" part):
>
> package require dom
> set xml_image {<?xml version = "1.0" encoding = "UTF-8" ?>
> <via id="1" trivia_id="255" question="How much wood would a
> woodchuck chuck?" answer_id="1" answer="A lot"
> expDate="116494926"></via>}
> set doc [dom::parse $xml_image]
> set result {}
> foreach node [dom::selectNode $doc //@*] {
> lappend result [dom::node configure $node -localName] \
> [dom::node stringValue $node]
> }
> puts $result


I'm probably not the best one to respond to this, but why not

It looks very elegant in TCL, but if you talk to someone that can't
fathom XML parsing like me, you look at it and say to yourself
"Gesundheit!"

Whereas in PHP I read this and while not understanding XML parsing, I
know the bottom line: it works, it's simple and I know what to do with
the array result:

Phil


>
> When I run this, I see
>
> id 1 trivia_id 255 question {How much wood would a woodchuck chuck?} answer_id 1 answer {A lot} expDate 116494926
>
> I leave to others judgment of how this compares to the PHP
> script cited for clarity, concision, and so on.
>
> Thanks to Steve for his great achievements with TclXML, and
> his kind help to me understanding its proper use.


Cameron Laird

2006-11-28, 7:11 pm

In article <1164699810.928526.109740@14g2000cws.googlegroups.com>,
comp.lang.tcl <phillip.s.powell@gmail.com> wrote:
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com