|
Posted by comp.lang.tcl on 11/25/06 18:37
Michael Schlenker wrote:
> comp.lang.tcl schrieb:
> > 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"); } ?>
> > [/PHP]
> >
> > 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("<?xml
> > version="1.0" encod": file name too long
> > [/quote]
> >
> > 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.
> >
> 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 confused 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
[Back to original message]
|