|
Posted by Michael Schlenker on 11/25/06 18:27
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.
Michael
Navigation:
[Reply to this message]
|