For Programmers: Free Programming Magazines  


Home > Archive > Tcl > November 2006 > TCL/PHP/XML problem: I need to convert an XML file into a TCL 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 TCL/PHP/XML problem: I need to convert an XML file into a TCL list
comp.lang.tcl

2006-11-25, 8:02 am

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}

This is the TCL code that does this:

[TCL]
set contents [read $fileID [file size ${fileName}.xml]]; close $fileID


if {![string equal $switch -body]} {
# ONLY DO THIS IF THE XML CONTENTS CONTAIN NO BODY - WILL UPGRADE AT
A LATER DATE 11/24/2006 - PHIL
global serverName
if {![info exists serverName]} {
global env
source ./cgi_globals.tcl
global serverName
}

if {[string length [info procs {URL_ENCODE}]] == 0} { source
../url_procs.tcl }; # INCLUDE NEW url_procs.tcl URL TCL LIBRARY
if {[string length [info procs {IS_LIST}]] == 0} { source
{./tcl_string_tools.tcl} }; # INCLUDE THE TCL STRING LIBRARY CONTAINING
PROC is_list IF !FOUND

# BLOCK TO CREATE THE PHP SCRIPT TO PIPE INTO php.exe
regsub -all {'} [XML_CLEANUP_ATTRIBUTE $contents] {\"}
phpEscapedContents
regsub -all {"} $phpEscapedContents {\"} phpEscapedContents
set php {<? }
append php [subst { if (@is_file("./functions.inc.php")) [format %c
123] }]
append php { require_once("./functions.inc.php"); }
append php [subst { echo xml_to_tcl_list("$phpEscapedContents"); }]
append php [subst {[format %c 125] }]
append php { ?>}


set cannotRunPHP [catch {exec "echo '$php' | php" >@stdout
2>&stderr} errorMsg]
if {$cannotRunPHP} {
puts $errorMsg
return {}
} else {
if {![IS_LIST $contentsList]} { set contentsList [split
$contentsList] }
if {[llength $contentsList] == 0} { lappend contentsList {?} }
return [lrange $contentsList [expr {[lsearch -exact $contentsList
"?"] + 1}] end]
}

}
[/TCL]

The command-line PHP should look like this:

PHP:

<? if (@is_file("./functions.inc.php")) {
require_once(
"./functions.inc.php"); echo
xml_to_tcl_list("$phpEscapedContents"); }  ?>



Note that $phpEscapedContents is a TCL variable, not a PHP variable

Ok, so this is what should happen:

1) PHP function xml_to_tcl_list will convert the inputted escaped XML
string into a TCL list
2) I need to return that TCL list into $contentsList and return it so
the proc returns a TCL list

However, it never gets that far, here is the error I get:

quote:

couldn't execute "echo '<? if (@is_file("./functions.inc.php")) {
require_once("./functions.inc.php"); echo xml_to_tcl_list("&lt;?xml
version="1.0" encod": file name too long



I am sure I am going at this the wrong way, but I can't understand the
right way (TCL DOM parsing is far FAR beyond my ability to understand,
I've read manuals, tutorials, books, to no avail: I simply don't
understand how TCL can ever parse XML, I only understand simple PHP
parsing XML)

So at this point, all I want to do is convert an XML string into a TCL
list, and the only way I know how to do it is via PHP, but I can't get
all three languages to cooperate.

Help appreciated.

Thanx
Phil

comp.lang.tcl

2006-11-25, 7:02 pm


Bryan Oakley wrote:
> comp.lang.tcl wrote:
>
> You need to re-read the man page on exec. The first argument to exec is
> a filename that will be exec'd; it is not a command line. If you want to
> run a command line you should exec a command line processor (/bin/sh,
> command.com, whatever).
>
> Since "php" is what you want to exec, and $php is what you want to send
> to its stdin, use "<<" (documented on the exec man page):
>
> if {[catch {exec php << $php} result]} {
> puts "error exec'ing php: $resulut"
> } else {
> puts "php result: $result"
> }



Now I get this error:

couldn't execute "php": no such file or directory

When I try this:

[TCL]
set cannotRunPHP [catch {exec exec php << $php >@stdout 2>&stderr}
errorMsg]
if {$cannotRunPHP} {
puts $errorMsg
return {}
} else {
if {![IS_LIST $contentsList]} { set contentsList [split
$contentsList] }
if {[llength $contentsList] == 0} { lappend contentsList {?} }
return [lrange $contentsList [expr {[lsearch -exact $contentsList
"?"] + 1}] end]
}

[/TCL]

Wow this should only take an hour, it's taken 3 days so far!

Phil
>
> You can read a wiki page on the subject here: http://mini.net/tcl/exec


comp.lang.tcl

2006-11-25, 7:02 pm


Michael Schlenker wrote:
> comp.lang.tcl schrieb:
> If you showed us part of the XML there surely is a shorter way with one
> of the XML parsers for Tcl like tdom, but maybe your just by
> the difference between DOM and SAX style xml parsing.


There is, but I've said this to nearly ever TCL and PHP developer on
earth: I do not understand XML parsing at all, DOM, SAX, xQuery,
X[whatever else], none of it makes sense to me and I cannot understand
the books, tutorials and online guides (not to mention the tips from
far smarter people than I) that has barraged me; all of it makes
absolutely no sense to me.

At this point the only way I can parse XML is using PHP, because that's
literally the ONLY way I can do it, period!

But if you want to see a sample of the XML I'm working with, here it
is:

<?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>

Phil


>
> Michael


comp.lang.tcl

2006-11-25, 7:02 pm


Bryan Oakley wrote:
> comp.lang.tcl wrote:
>
> When you are learning a new language, it always takes much longer to
> solve problems. And in your case I'm afraid, you aren't taking much time
> to actually learn the language which is compounding the problem.
>
> The answer to your current problem is well documented in the exec man
> page, and on the exec pages on the tcler's wiki. The problem you are
> encountering is very simple: you are telling it to execute "php" but tcl
> can't find "php". The short answer is, you either have to explicitly
> tell the exec command which *file* to execute (eg: exec
> /usr/local/bin/php), or you have to make sure that the file you tell it
> exists somewhere within a directory defined in your PATH environment
> variable.
>
> Phil, I'm sorry you're having so many problems. You are correct that
> this probably should have taken only an hour or two for a seasoned
> programmer, but you are not a seasoned programmer and properly parsing
> XML is, generally speaking, a Hard Problem. At least, it's hard when you
> choose to not use proper XML parsing solutions and instead rely on a
> series of text transformations.
>


Bryan, you're going to die when you hear this: I have 9+ years web
development experience, been doing TCL for about 7 years (mostly via
Vignette), have 5 certifications including a master PHP certification..
and I have no clue how to do any of this. Thus I am a seasoned
programmer (though honestly nobody here will ever recognize or believe
that)


> Tcl is a very powerful language, but it doesn't have built-in facilities
> to parse XML. This is not a weakness of Tcl, it's just the way it is.
> The beauty of Tcl is, people can write extensions to the language to do
> just about anything, including parsing XML. Unfortunately, you are
> choosing not to take the time to learn how to use them.


I've said this over and over again: it's not that I won't take the
time, it's that I CANNOT do it because I have a learning disability
called Attention Deficit Disorder which psychologically does not permit
me to take the time to learn it. I am unable to understand man pages
like you and Cameron and other can do in your sleep. I read the Tcl
extensions online but don't understand them. The pages are in
Hungarian to me. I can't fathom them, I don't know how to install
them, manipulate them, use them, anything. If people could show me a
very very simple way of parsing this:

<?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>

Into this:

id 1101 triviaID 233 question {Who wrote "Trilogy of
Knowledge"?} answerID 1 correctAnswerID 1 answer Believer expDate
113963500

[etc]

Then that would do it, but I guess the problem is that I can't explain
my problem, nor my disabilities, well enough for the programming
community to fathom my dilemma.

Phil

>
> I'll again recommend trying the xml2list function documented here:
> http://mini.net/tcl/3919. I'm guessing that will work good enough for
> you. Fortunately, it appears you're working on a simply hobby
> application rather than a commercial application so we don't have to
> worry so much about robustness.


comp.lang.tcl

2006-11-25, 7:02 pm


Bryan Oakley wrote:
> comp.lang.tcl wrote:
>
> That data is mal-formed XML. For example, you are missing the closing
> </trivia> tag.
>
> Here's a solution that works with the above data. I've mentioned the
> "xml2list" proc a couple of times, but with the sample data I see your
> data will need a little extra pre-processing.
>
> Step 1: copy the proc "xml2list" from this page: http://mini.net/tcl/3919


Ok done

>
> Second, enter the following, which is taking the above data verbatim and
> storing it in a variable:
>
> set data {<?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>}
>
> Your data is missing an ending </trivia> tag, so we have to add it for
> this specific example. I don't know if this is a problem you'll have to
> solve with your full dataset. Also, the xml2list proc doesn't like the
> leading <?xml...> stuff. So, let's modify your data:



Sorry that was my fault, I left off the </trivia> tag when I copied and
pasted onto here. The closing tags do exist in all of my XML files

>
> # remove the leading <?xml...?> data
> regexp {<\?.*?\?>(.*$)} $data -- data
>
> # add a trailing </trivia> which is missing from
> # the sample data
> set data "$data</trivia>"
>
> And now, convert it to a list and print it out:
>
> set result [xml2list $data]
> puts $result
>
> If you didn't introduce any typos, you'll get the following output:



No I don't, I get the following error, spawned from within xml2list:

unmatched open quote in list while executing "lindex $item 0"
("default" arm line 2) invoked from within "switch -regexp -- $item {
^# {append res "{[lrange $item 0 end]} " ; #text item} ^/ { regexp
{/(.+)} $item -> ..." (procedure "xml2list" line 9)

This is what I did:

[TCL]
# USE xml2list PROC WITHIN THIS LIBRARY AS YOUR DEFAULT MEANS OF
PARSING XML INTO TCL LIST
if {![string equal $switch -body] && [string length [info procs
{xml2list}]] > 0} {
regexp {<\?.*?\?>(.*$)} $contents -- contents
return [xml2list $contents]
}
[/TCL]

>
> trivia {} {{entry {id 1101 triviaID 233 question {Who wrote
> "Trilogy of Knowledge"?} answerID 1 correctAnswerID 1 answer
> Believer expDate 1139634000} {}} {entry {id 1102 triviaID 233 question
> {Who wrote "Trilogy of Knowledge"?} answerID 2 correctAnswerID
> 1 answer {Saviour Machine} expDate 1139634000} {}} {entry {id 1103
> triviaID 233 question {Who wrote "Trilogy of Knowledge"?}
> answerID 3 correctAnswerID 1 answer {Seventh Avenue} expDate 1139634000}
> {}} {entry {id 1104 triviaID 233 question {Who wrote "Trilogy of
> Knowledge"?} answerID 4 correctAnswerID 1 answer {Inevitable End}
> expDate 1139634000} {}} {entry {id 1105 triviaID 233 question {Who wrote
> "Trilogy of Knowledge"?} answerID 5 correctAnswerID 1 answer
> {No such song existed} expDate 1139634000} {}}}
>
> The above is a valid tcl list that you can now process with normal tcl
> list-handling commands. Do *not* process this list with string
> transformations (such as converting " to a quote). If you do, you
> run the risk of breaking it's list-ness. Instead, loop over the data and
> do the conversion as a final step on a element-by-element basis.
>
> Does this help? It's not robust; the xml2list assumes you have proper
> xml with a balanced set of tags (or in the specific case in this
> message, with a missing </trivia> tag). Hopefully, though, it will at
> least get you started.


Like I said, I do have balanced XML (just didn't produce it here tis
all), but xml2list produces errors when I try to read it

Phil

comp.lang.tcl

2006-11-25, 7:02 pm


Bryan Oakley wrote:
> comp.lang.tcl wrote:
>
> Ok, so what you're saying is you did not execute my example verbatim.
> You need to first test with the exact code and data in my post to make
> sure it will work for at least some subset of data. I'm not convinced
> you did that since your example uses $contents. Maybe you just switched
> variable names, but I suspect your $contents doesn't contain the exact
> sample data you gave us.


[TCL]
# USE xml2list PROC WITHIN THIS LIBRARY AS YOUR DEFAULT MEANS OF
PARSING XML INTO TCL LIST
if {![string equal $switch -body] && [string length [info procs
{xml2list}]] > 0} {
set contents {<?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>}
regexp {<\?.*?\?>(.*$)} $contents -- contents
puts [xml2list $contents]
return [xml2list $contents]
}
[/TCL]

produces the correct list results, but why? Why is this fails then:

[TCL]
set contents [read $fileID [file size ${fileName}.xml]]; close $fileID

# USE xml2list PROC WITHIN THIS LIBRARY AS YOUR DEFAULT MEANS OF
PARSING XML INTO TCL LIST
if {![string equal $switch -body] && [string length [info procs
{xml2list}]] > 0} {
regexp {<\?.*?\?>(.*$)} $contents -- contents
puts "$contents<P><P>"
puts [xml2list $contents]
return [xml2list $contents]
}

[/TCL]

Which produces:

unmatched open quote in list while executing "lindex $item 0"
("default" arm line 2) invoked from within "switch -regexp -- $item {
^# {append res "{[lrange $item 0 end]} " ; #text item} ^/ { regexp
{/(.+)} $item -> ..." (procedure "xml2list" line 9)

And never produces $contents whatsoever?

Phil


>
> Since I can't duplicate your runtime environment (some sort of web
> server, apparently) and I can't duplicate your data, I'm at a loss to help.
>
> My guess is, the value of $contents varies from the sample data in some
> significant way. The best way to proceed is to first make sure you can
> get working results with the sample data you provided. Then, we can
> tackle why your real data gets different results.


comp.lang.tcl

2006-11-25, 7:02 pm

[TCL]
# USE xml2list PROC WITHIN THIS LIBRARY AS YOUR DEFAULT MEANS OF
PARSING XML INTO TCL LIST
if {![string equal $switch -body] && [string length [info procs
{xml2list}]] > 0} {
regexp {<\?.*?\?>(.*$)} $contents "\\1" contents
puts "$contents<P><P>"
return $contents
}
[/TCL]

Produces

<fortune><saying id="1" author="Phil Powell" phrase="New York is SO
Superior!"></saying><saying id="2" author="Phil Powell" phrase="SUBMIT
STUFF!"></saying><saying id="3" author="Old Screams of Abel Slogan"
phrase="Sanctify the Underground!"></saying><saying id="4" author="Phil
Powell" phrase="I believe animals have rights.. they have a right to be
on my dinner plate"></saying><saying id="5" author="Lars Walker"
phrase="..The minimalist approach is also interesting. Sort of a
Scandinavian Modern web site"></saying><saying id="6" author="Phil
Powell" phrase="Don't forget to sign the guestbook!"></saying><saying
id="7" author="Phil Powell" phrase="Jag vill tillbaka till mitt
hemland!"></saying><saying id="8" author="Phil Powell" phrase="Let us
sit by the bonfire, roasting slabs of meat, telling tales of musical
conquest"></saying><saying id="9" author="Phil Powell" phrase="Want to
know God's wonderous sense of grace? You still exist."></saying><saying
id="10" author="Phil Powell" phrase="Gud Rockar - God
Rocks!"></saying><saying id="11" author="Phil Powell" phrase="I need
CAFFEINE!"></saying><saying id="12" author="Micah 4:6-7 (NKJV)"
phrase=""In that day" says the Lord, "I will assemble
the lame, I will gather the outcast, And those whom I have afflicted; I
will make the lame a remnant, And the outcast a strong nation; So the
Lord will reign over them in Mount Zion From now on, even
forever.""></saying><saying id="13" author="Edgar Allen Poe"
phrase="We are all insane with long intervals of
sanity..."></saying><saying id="14" author="C. S. Lewis"
phrase="Atheism is simple. Real things are not
simple."></saying><saying id="15" author="Phil Powell"
phrase="Nietzsche denied and mocked God, then died insane..
hmm.."></saying><saying id="16" author="Keltin Alexander" phrase="How
can you save those in darkness?
You must be unafraid to enter the darkness, and let your light shine
forth to every corner.
"></saying><saying id="17" author="Phil in reply to
"satanists"" phrase=""..the serpent was created by a god
that doesn't exist..".. Oh, so Satan doesn't exist
either??!!"></saying><saying id="18" author="Matt's interpretation of
"Screams of Abel"" phrase="Cain, no! Noo no please no! that's
a really big rock Cain, nooooo, Mom won't like this a bit! owww Cain,
now stop that! ouch! you hit like a girl, put that rock down right now
little brother! owww"></saying><saying id="19" author="overheard in
chatroom" phrase="5 out of 10 cannibals agree that vegetarians taste
better.."></saying><saying id="20" author="My London Family"
phrase=""Thank you, please!""></saying><saying id="21"
author="St.Augustine (354-430 AD)" phrase="In Essentials, unity. In
non-essentials, liberty. In all things, love"></saying><saying id="22"
author="On t-shirts in Norway" phrase="I wear black until they invent a
darker colour!!"></saying><saying id="23" author="from "Dune"
(1985)" phrase="One cannot go against the Word of
God"></saying></fortune>

Now my site won't load at all!! http://valsignalandet.com

Bryan, what do I do?

Phil

comp.lang.tcl

2006-11-25, 7:02 pm


Darren New wrote:
> comp.lang.tcl wrote:
>
> Take the zip file I posted. Install it. Call


Sorry there is no attachment, no zip file of any kind.

Phil


>
> set x [::xsxp::parse $myXml]
> return [lindex [lindex $x 2] 1]
>
> (I think that's the right path thru the list to the attributes of the
> first child element. Otherwise, print out the list and see which
> elements you have to grab.)
>
> --
> Darren New / San Diego, CA, USA (PST)
> Scruffitarianism - Where T-shirt, jeans,
> and a three-day beard are "Sunday Best."


comp.lang.tcl

2006-11-25, 7:02 pm


Cameron Laird wrote:
> In article <tt0ah.6413$yf7.3870@newssvr21.news.prodigy.net>,
> Bryan Oakley <oakley@bardo.clearlight.com> wrote:
> .
> .
> .
> .
> .
> .
> Alternatively, as Bryan knows, but doubtless eschewed for
> pedagogic reasons,
>
> append data </trivia>


Why? The XML files are not being auto-spawned by TCL or anything else!

comp.lang.tcl

2006-11-25, 7:02 pm


Bryan Oakley wrote:
> comp.lang.tcl wrote:
>
> The answer to "why" is something along the lines of "because the live
> data is different from the sample data" and/or "xml2list wasn't designed
> to work with XML in your specific format", and it seems to have
> something to do with quotations.
>
> Remember: xml2list is just a simple hack. It's not actually parsing the
> xml, it's just making a weak attempt at converting it to a list by
> replacing <foo with "{foo" and > with "} ", or something to that effect.
> It is very similar to your original program -- it does some simple text
> transforms then assumes the result is a list. If there is data it's not
> expecting it all falls down like a house of cards.


I've given up on xml2list, I don't think it'll work with the XML data I
have, I'm sorry. I don't honestly know what else to do at this point,
but the fact is that the site is breaking and going into now infinite
loops (perhaps segfaults) as a result of my inability to do the very
simple task of converting XML into a TCL list.

Phil

Mark Janssen

2006-11-25, 10:05 pm



On Nov 26, 2:11 am, "Gerald W. Lester" <Gerald.Les...@cox.net> wrote:
> comp.lang.tcl wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> for a different OS.
>
> Seehttp://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).
>
>


Which was actually the kit I unpacked with SDX and put in a zip-file to
make it easier to install in the parallel thread and that didn't seem
to work.

Mark

comp.lang.tcl

2006-11-25, 10:05 pm


Mark Janssen wrote:
> On Nov 26, 2:11 am, "Gerald W. Lester" <Gerald.Les...@cox.net> wrote:
>
> Which was actually the kit I unpacked with SDX and put in a zip-file to
> make it easier to install in the parallel thread and that didn't seem
> to work.



That was the exact build I downloaded and unzipped onto my directory at
www.clearlight.com and the admin told me it was not compatible. I was
unable to configure it, neither was he, it won't install beyond just
sitting in the directory and that's it.

Phil
>
> Mark


comp.lang.tcl

2006-11-25, 10:05 pm


Mark Janssen wrote:
> On Nov 26, 2:11 am, "Gerald W. Lester" <Gerald.Les...@cox.net> wrote:
>
> Which was actually the kit I unpacked with SDX and put in a zip-file to
> make it easier to install in the parallel thread and that didn't seem
> to work.
>
> Mark


**update**

OK I'm sorry I downloaded the wrong package, I got your tdom.zip,
unzipped it and put it on /home/ppowell/web/cgi-bin

added this to xml_procs.tcl

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

Here are the results:

/usr/lib/dld.sl: Can't open shared library:
/home/ppowell/web/cgi-bin/HP-UX-9000/785/tdom.sl /usr/lib/dld.sl: No
such file or directory /usr/lib/dld.sl: Can't open shared library:
/home/ppowell/web/cgi-bin/HP-UX-9000/785/tdom.sl /usr/lib/dld.sl: No
such file or directory error reading package index file
/home/ppowell/web/cgi-bin/pkgIndex.tcl: couldn't load file
"/home/ppowell/web/cgi-bin/HP-UX-9000/785/tdom.sl": no such file or
directory /usr/lib/dld.sl: Can't open shared library:
/home/ppowell/web/cgi-bin/HP-UX-9000/785/tdom.sl /usr/lib/dld.sl: No
such file or directory /usr/lib/dld.sl: Can't open shared library:
/home/ppowell/web/cgi-bin/HP-UX-9000/785/tdom.sl /usr/lib/dld.sl: No
such file or directory couldn't load file
"/home/ppowell/web/cgi-bin/HP-UX-9000/785/tdom.sl": no such file or
directory while executing "load "[file join $dir [platform] $lib]""
(procedure "loadlib" line 6) invoked from within "loadlib
/home/ppowell/web/cgi-bin tdom 0.7.8" ("package ifneeded" script)
invoked from within "package require tdom"

Mark Janssen

2006-11-25, 10:05 pm



On Nov 26, 2:54 am, "comp.lang.tcl" <phillip.s.pow...@gmail.com> wrote:
> Mark Janssen wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> OK I'm sorry I downloaded the wrong package, I got your tdom.zip,
> unzipped it and put it on /home/ppowell/web/cgi-bin
>
> added this to xml_procs.tcl
>
> lappend auto_path /home/ppowell/web/cgi-bin
> package require tdom
>
> Here are the results:
>
> /usr/lib/dld.sl: Can't open shared library:
> /home/ppowell/web/cgi-bin/HP-UX-9000/785/tdom.sl /usr/lib/dld.sl: No
> such file or directory /usr/lib/dld.sl: Can't open shared library:


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")

Good luck,
Mark

comp.lang.tcl

2006-11-25, 10:05 pm


Gerald W. Lester wrote:
> Mark Janssen wrote:
>
> 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.


Sorry but there is no budget for that one :( I was hoping for a more
public-domain download than this, anything out there?

Phil

>
> --
> +--------------------------------+---------------------------------------+
> | Gerald W. Lester |
> |"The man who fights for his ideals is the man who is alive." - Cervantes|
> +------------------------------------------------------------------------+


comp.lang.tcl

2006-11-25, 10:05 pm


Gerald W. Lester wrote:
> comp.lang.tcl wrote:
>
> It is free as long as you do not ship it.


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

Phil


>
> --
> +--------------------------------+---------------------------------------+
> | Gerald W. Lester |
> |"The man who fights for his ideals is the man who is alive." - Cervantes|
> +------------------------------------------------------------------------+


Ramon Ribó

2006-11-26, 8:03 am



package require tdom

set doc [dom parse {<?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>}]

set res ""
foreach domNode [$doc selectNodes ./*/*/attribute::*] {
eval lappend res $domNode
}
puts $res

--->

id 1101 triviaID 233 question {Who wrote "Trilogy of Knowledge"?} answerID
1 correctAnswerID 1 answer Believer expDate 1139634000 id 1102 triviaID
233 question {Who wrote "Trilogy of Knowledge"?} answerID 2
correctAnswerID 1 answer {Saviour Machine} expDate 1139634000 id 1103
triviaID 233 question {Who wrote "Trilogy of Knowledge"?} answerID 3
correctAnswerID 1 answer {Seventh Avenue} expDate 1139634000 id 1104
triviaID 233 question {Who wrote "Trilogy of Knowledge"?} answerID 4
correctAnswerID 1 answer {Inevitable End} expDate 1139634000 id 1105
triviaID 233 question {Who wrote "Trilogy of Knowledge"?} answerID 5
correctAnswerID 1 answer {No such song existed} expDate 1139634000


Ramon Ribó

En Sat, 25 Nov 2006 19:53:21 +0100, comp.lang.tcl
<phillip.s.powell@gmail.com> escribió:
of parsing this:

<?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>

Into this:
Steve Ball

2006-11-26, 7:04 pm

> I've said this over and over again: it's not that I won't take the
> time, it's that I CANNOT do it because I have a learning disability
> called Attention Deficit Disorder which psychologically does not permit
> me to take the time to learn it.


I'm sorry to hear that you have problems, but is that an excuse not to
RTFM?

I'll try and helpout with a simple solution. Note that your input XML
and the result that you want is very, how do I put it?, weird. This
solution will not suit many other applications (iow, don't try this at
home, kids).

Your source XML looks like this:
> <?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>

....

So, a bunch of <entry> elements where the real data is in attributes.
This looks like a dump of a relational database to me.

> Into this:
>
> id 1101 triviaID 233 question {Who wrote "Trilogy of
> Knowledge"?} answerID 1 correctAnswerID 1 answer Believer expDate
> 113963500


Yup, and then you're recreating the relational data in Tcl.

NB. XML is not the problem here - you may as well have just used CSV
rather than XML.

A SAX-style interface is problem the easiest way to get what you want.
Here's the solution:

package require xml

namespace eval xml2list {
namespace export convert
variable accumulator
}

proc xml2list::convert xml {
variable accumulator

# we only need to know about the start of elements,
# so create a parser and set the start-element callback
set parser [xml::parser -elementstartcommand [namespace code Start]]
set accumulator {}

# let 'er rip
$parser parse $xml ;# not handling errors

# the result will be in the accumulator
return $accumulator
}

# This procedure gets called for every start tag
proc xml2list::Start {tag attlist args} {
variable accumulator

# the parser has already done the work of turning the
# attributes into a list
lappend accumulator $attlist

return {}
}

### end of script

Notes:

1. This solution is single-threaded. It is an exercise for the reader
to have it run multi-threaded.
2. Attributes as Tcl lists is probably not ideal - a dict would be
better. However, in this case lists are necessary to represent the
relational data.

HTHs,
Steve Ball

comp.lang.tcl

2006-11-27, 7:05 pm


Gerald W. Lester wrote:
> comp.lang.tcl wrote:
>
> 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).


I just plain didn't know what to do so I probably overdid it, did a scp
-pr of the entire tdom0.8.1 directory for HP-UX over to the remote site
under /cgi-bin, and when I put this on the top of xml_procs.tcl, it did
not produce any kind of syntax or evaluation error:

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

Now, going to http://wiki.tcl.tk/8984 to try to understand tdom, I have
no idea what this site is talking about. All I want to do is take
every attribute key => val pair and convert it to a well-ordered TCL
list, and this site does not explain it to me in such a way that I'd
understand.

Thanx though so far, sorry I'm so nearly impossible to handle!

Phil

>
>
> --
> +--------------------------------+---------------------------------------+
> | Gerald W. Lester |
> |"The man who fights for his ideals is the man who is alive." - Cervantes|
> +------------------------------------------------------------------------+


suchenwi

2006-11-27, 7:05 pm

OK, here's a hopefully real simple example with tdom (done in an
interactive tclsh):

#------------------------- create an example XML buffer
% set xml {<foo><bar a="1" b="2" c="3"/><bar a="uno" b="dos" c="tres"
/></foo>}
<foo><bar a="1" b="2" c="3"/><bar a="uno" b="dos" c="tres" /></foo>

#----------------------------- make sure we get tdom
% package require tdom
080

#------------------------------ parse our buffer, get a handle to its
root node
% set root [[dom parse $xml] documentElement]
domNode00BE1140

#----------------------------- dump the root (and everything below it)
as a list of lists
% $root asList
foo {} {{bar {a 1 b 2 c 3} {}} {bar {a uno b dos c tres} {}}}

#------------------------------ walk over all the attribute contents:
% foreach i [lindex [$root asList] 2] {puts item=[lindex $i 1]}
item=a 1 b 2 c 3
item=a uno b dos c tres

comp.lang.tcl

2006-11-27, 7:05 pm


suchenwi wrote:
> OK, here's a hopefully real simple example with tdom (done in an
> interactive tclsh):
>
> #------------------------- create an example XML buffer
> % set xml {<foo><bar a="1" b="2" c="3"/><bar a="uno" b="dos" c="tres"
> /></foo>}
> <foo><bar a="1" b="2" c="3"/><bar a="uno" b="dos" c="tres" /></foo>
>
> #----------------------------- make sure we get tdom
> % package require tdom
> 080
>
> #------------------------------ parse our buffer, get a handle to its
> root node
> % set root [[dom parse $xml] documentElement]
> domNode00BE1140


Ok, break it down for me, what's a node? I honestly don't know.

>
> #----------------------------- dump the root (and everything below it)
> as a list of lists
> % $root asList
> foo {} {{bar {a 1 b 2 c 3} {}} {bar {a uno b dos c tres} {}}}
>
> #------------------------------ walk over all the attribute contents:
> % foreach i [lindex [$root asList] 2] {puts item=[lindex $i 1]}
> item=a 1 b 2 c 3
> item=a uno b dos c tres


ah thanx I will try that!
Phil

Cameron Laird

2006-11-28, 4:06 am

In article <1164575063.770613.309370@l12g2000cwl.googlegroups.com>,
Steve Ball <Steve.Ball@explain.com.au> wrote:
comp.lang.tcl

2006-11-28, 4:06 am


Cameron Laird wrote:
> In article <1164575063.770613.309370@l12g2000cwl.googlegroups.com>,
> Steve Ball <Steve.Ball@explain.com.au> wrote:
> .
> .
> .
> I think this part VERY MUCH deserves repetition.
> It is indeed ... silly to serialize relational
> data into XML on the way to Tcl.
> .
> .
> .
> I'm all in favor of dicts.


Dicts? What is a dict? Again I don't know your terminology

BTW I use XML and not CSV because I would have to rewrite too much of
the site to handle CSV instead of XML, and BTW did I mention that I
have no idea how to handle CSV via TCL in the first place, much less
XML?

I think that you may have to understand that I am not exactly on the
same learning curve with the rest of comp.lang.tcl, apparently a gaggle
of very seasoned engineers with multiple TCL experience, and I'm this
web guy that has ADD. I'm learning as best as I can, but Cameron,
please, you're making me drink from a firehose here!

Oh and BTW this is not a database relational dump. There is no
database; the server that hosts that site has no database and no
business plans to ever implement one.

Phil

>
> I don't understand the comment about threading.
> How is concurrency an issue at all?
> .
> .
> .


Cameron Laird

2006-11-28, 4:06 am

In article <1164575063.770613.309370@l12g2000cwl.googlegroups.com>,
Steve Ball <Steve.Ball@explain.com.au> wrote:
Sponsored Links







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

Copyright 2008 codecomments.com