ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> tclxml-users
tclxml-users
Re: [Tclxml-users] TclXML confusions (was: How can I ensure that I always have a list?)
by Steve Ball other posts by this author
Nov 26 2006 1:05PM messages near this date
[Tclxml-users] TclXML confusions (was: How can I ensure that I always have a list?) | [Tclxml-users] TCLXML question
Cameron, et al,

(I can't find the c.l.t. thread for this message; Cameron, would you  
please forward to the newsgroup?)

The subcommand is "selectNode".  This is a misnomer since one is  
usually selecting multiple nodes.  Since it is a non-standard feature  
it is at the DOMImplementation level, rather than at the Document  
level.  Its use is like so:

set nodes [dom::selectNode $doc //via]

selectNode returns a static node list, which in terms of TclDOM means  
a normal Tcl 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.  Bear in mind that the  
DOM and XPath data models are not entirely compatible, so this is not  
trivial.

This doesn't seem to be quite what the original message was asking.   
To get an element's attributes as a list you can use TclXML (ie. the  
SAX-like interface).  This delivers the attributes of an element as a  
Tcl list, as desired.  But which element?  You have to write your own  
code to figure that out.

This is where XPath is better.  //@* would give you every attribute  
of every element in the document.  //via/@* would give you every  
attribute of every "via" element in the document (not just of the  
document/root element).  The variations are almost endless.  However,  
you need a DOM tree to do this.

HTHs,
Steve Ball

On 26/11/2006, at 5:16 AM, Cameron Laird wrote:

>  In article <jijl34-ipc.ln1@[...].us>, I recommended:
> > In article <1164440504.571107.104710@[...].com>,
> > comp.lang.tcl <phillip.s.powell@[...].com> wrote:
> > 			.
> > 			.
> > 			.
> >>> What exactly are you attempting to do?
> >>
> >> It's so easy.  All I want to do is convert an XML file into a TCL  
> >> list,
> >> that's it, just a TCL list:
> >>
> >> attr1 {val1} attr2 {val2}
> > 			.
> > 			.
> > 			.
> > 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/group/comp.lang.tcl/messages/ 
>  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?
> 


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Tclxml-users mailing list
Tclxml-users@[...].net
https://lists.sourceforge.net/lists/listinfo/tclxml-users
Thread:
Cameron Laird
Steve Ball

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved