Reply to Re: TCL/PHP/XML problem: I need to convert an XML file into a TCL list

Your name:

Reply:


Posted by comp.lang.tcl on 11/25/06 23:39

Gerald W. Lester wrote:
> comp.lang.tcl wrote:
> > My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML
> > file into a TCL list as follows:
> >
> > attr1 {val1} attr2 {val2} ... attrN {valN}
>
> First off, sorry to everyone else for the long post, but I got tired reading
> these threads.
>
> Second off, the following does not return *EXACTLY* what you asked for it
> returns more, but you should be able to convert it to what you ask for.
>
> ##
> ## A node will be the following list of name value pairs:
> ## NAME nodeName
> ## TEXT text
> ## ATTRIBUTES attributeNameValueList
> ## CHILDREN childNodeList
> ##
> package require tdom

Sorry I am unable to figure out how to install and use tdom. I tried
this

lappend auto_path /home/ppowell/web/cgi-bin
package require tdom

at the top of xml_procs.tcl, to no avail, I get the following error:

can't find package tdom while executing "package require tdom" (file
"xml_procs.tcl" line 2)

I was able to download and install tdom, or I guess install it:

1) I downloaded it

2) I unzipped it

3) everything's in /home/ppowell/web/cgi-bin/tDom-0.8.0

4) I was not allowed to do ../configure, much less "make" nor "make
install", "../configure" not found

Phil

>
> set xml {<?xml version="1.0" encoding="utf-8" ?>
> <trivia>
> <entry id="1101" triviaID="233" question="Who wrote &quot;Trilogy
> of Knowledge&quot;?" answerID="1" correctAnswerID="1" answer="Believer"
> expDate="1139634000"></entry>
> <entry id="1102" triviaID="233" question="Who wrote &quot;Trilogy
> of Knowledge&quot;?" answerID="2" correctAnswerID="1" answer="Saviour
> Machine" expDate="1139634000"> </entry>
> <entry id="1103" triviaID="233" question="Who wrote &quot;Trilogy
> of Knowledge&quot;?" answerID="3" correctAnswerID="1" answer="Seventh
> Avenue" expDate="1139634000"></entry>
> <entry id="1104" triviaID="233" question="Who wrote &quot;Trilogy
> of Knowledge&quot;?" answerID="4" correctAnswerID="1" answer="Inevitable
> End" expDate="1139634000"></entry>
> <entry id="1105" triviaID="233" question="Who wrote &quot;Trilogy
> of Knowledge&quot;?" answerID="5" correctAnswerID="1" answer="No such song
> existed" expDate="1139634000"></entry>
> </trivia>
> }
>
> ##
> ## Convert a node to a list
> ##
> proc NodeToList {node} {
> ##
> ## Get the name and text value of the node
> ##
> set name [$node nodeName]
> set text [$node text]
>
> ##
> ## Get the attributes of the node
> ##
> set attrList {}
> foreach attribute [$node attributes] {
> lappend attrList $attribute [$node getAttribute $attribute]
> }
>
> ##
> ## Get the children of the node
> ##
> set childrenList {}
> foreach child [$node childNodes] {
> if {![string equal [$child nodeType] TEXT_NODE]} then {
> lappend childrenList [NodeToList $child]
> }
> }
>
> ##
> ## All done so return the list representing this subtree
> ##
> return [list NAME $name TEXT $text ATTRIBUTES $attrList CHILDREN
> $childrenList]
> }
>
> ##
> ## Convert the XML to a DOM tree
> ##
> dom parse $xml doc
>
> ##
> ## No get the root element
> ##
> $doc documentElement root
>
> ##
> ## Convert the tree to a list
> ##
> set results [NodeToList $root]
> $doc delete
>
>
> --
> +--------------------------------+---------------------------------------+
> | Gerald W. Lester |
> |"The man who fights for his ideals is the man who is alive." - Cervantes|
> +------------------------------------------------------------------------+

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация