Home > Archive > Tcl > November 2006 > Re: TCL/PHP/XML problem: I need to convert an XML file into a TCL
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 |
Re: TCL/PHP/XML problem: I need to convert an XML file into a TCL
|
|
| Gerald W. Lester 2006-11-25, 7:02 pm |
| 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
set xml {<?xml version="1.0" encoding="utf-8" ?>
<trivia>
<entry id="1101" triviaID="233" question="Who wrote "Trilogy
of Knowledge"?" answerID="1" correctAnswerID="1" answer="Believer"
expDate="1139634000"></entry>
<entry id="1102" triviaID="233" question="Who wrote "Trilogy
of Knowledge"?" answerID="2" correctAnswerID="1" answer="Saviour
Machine" expDate="1139634000"> </entry>
<entry id="1103" triviaID="233" question="Who wrote "Trilogy
of Knowledge"?" answerID="3" correctAnswerID="1" answer="Seventh
Avenue" expDate="1139634000"></entry>
<entry id="1104" triviaID="233" question="Who wrote "Trilogy
of Knowledge"?" answerID="4" correctAnswerID="1" answer="Inevitable
End" expDate="1139634000"></entry>
<entry id="1105" triviaID="233" question="Who wrote "Trilogy
of Knowledge"?" 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|
+------------------------------------------------------------------------+
| |
| Gerald W. Lester 2006-11-25, 10:05 pm |
| comp.lang.tcl wrote:
> comp.lang.tcl wrote:
He is on FreeBSD, he needs a build for that OS not linux.
[color=darkred]
>
> Ok took 20 mins but the admin was able to restore a backup of /cgi-bin
>
> Also he found out that tDOM is incompatible with the system on
> www.clearlight.com so I can't use it in any way shape or form
>
> So back to the drawing board :(
No, it is not incompatible -- just the build you were directed to is built
for a different OS.
See http://www.tdom.org/#SECTid80ac508
Download the kit (you may be able to source it in, if not unpack it on any
box using SDX and put the freebsd version on your webserver).
>
> Phil
>
--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
| |
| Gerald W. Lester 2006-11-25, 10:05 pm |
| Mark Janssen wrote:
>
>
> So it seems your website is hosted on a HP-UX platform, which the zip
> file (as you already discovered) does not contain binaries for. Because
> you cannot compile on that machine and I don't have HP-UX available, I
> cannot see a way forward in this direction.
> I think for your platform, the more promising possibility will then be
> to use a Tcl only solution (either TclXML or the proposals made here
> and in the "How can I ensure I always have a list thread")
ActiveState's (www.activestate.com) distro supports HP-UX (which is *not*
the same as FreeBSD) and has tdom in it.
Download it and at least put the tdom piece on your site.
--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
| |
| Gerald W. Lester 2006-11-25, 10:05 pm |
| comp.lang.tcl wrote:
> Gerald W. Lester wrote:
>
> Sorry but there is no budget for that one :( I was hoping for a more
> public-domain download than this, anything out there?
It is free as long as you do not ship it.
--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
| |
| Gerald W. Lester 2006-11-26, 4:21 am |
| comp.lang.tcl wrote:
> Gerald W. Lester wrote:
>
> Sorry, stupid moment.. I downloaded it, unzipped it, but what exactly
> do I move over to the HP-UX server? Do I just move tdom.tcl or do I
> move more than that?
>
> I am not able to install the entire ActiveState suite, we're not
> alloted that much room, sorry
Not sure on HP-UX where everything is, but on Windows it is all in the
tdom0.8.1 directory.
It should be at least: pkgIndex.tcl, tdom.tcl, tdom081.so (although this one
may have some other letters in its name).
--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
|
|
|
|
|