TCL / PHP / XML问题:我需要将XML文件转换为TCL列表 [英] TCL/PHP/XML problem: I need to convert an XML file into a TCL list
问题描述
我的TCL proc,XML_GET_ALL_ELEMENT_ATTRS,应该将XML
文件转换为TCL列表,如下所示:
attr1 {val1} attr2 {val2 } ... attrN {valN}
这是执行此操作的TCL代码:
[TCL]
设置内容[读取$ fileID [文件大小$ {fileName} .xml]];关闭$ fileID
if {![string equal $ switch -body]} {
#只有这样,如果XML内容不包含在内 - 将会升级到>
过去的日期11/24/2006 - PHIL
全局服务器名称
if {![info exists serverName]} {
global env
source ./cgi_globals.tcl
global serverName
}
if { [字符串长度[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 }}; #包含TCL STRING LIBRARY包含
PROC is_list IF!FOUND
#阻止创建PHP脚本以管理到php.exe
regsub -all {''} [XML_CLEANUP_ATTRIBUTE $ contents] {\}
phpEscapedContents
regsub -all {"} $ phpEscapedContents {\& ;}; phpEscapedContents
设置php {<?}
追加php [subst {if(@is_file(&.; ./ functions.inc.php")) [格式%c
123]}]
追加php {require_once(" ./ functions.inc.php");}
追加php [subst {echo xml_to_tcl_list(" $ phpEscapedContents");}]
追加php [subst {[format%c 125]}]
追加php {? >}
set cannotRunPHP [catch {exec" echo''$ php''| php"> @stdout
2>& stderr} errorMsg]
如果{$ cannotRunPHP} {
将$ errorMsg兑换成
返回{}
}其他{
如果{![IS_LIST $ contentsList]} {
set contentsList [split
$ contentsList]}
if {[llength $ contentsList] == 0} {lappend contentsList {?}}
return [lrange $ contentsList [expr {[lsearch -exact $ contentsList
"?"] + 1}] end]
}
>
}
[/ TCL]
命令行PHP应如下所示:
[PHP]
<? if(@is_file(&.; ./ functions.inc.php")){
require_once(&.; ./ functions.inc.php"); echo
xml_to_tcl_list(" $ phpEscapedContents"); }?>
[/ PHP]
注意$ phpEscapedContents是一个TCL变量,而不是PHP变量
好的,这就是应该发生的事情:
1)PHP函数xml_to_tcl_list将输入的转义XML
字符串转换为TCL列表
2)我需要将该TCL列表返回到$ contentsList并返回它
proc返回一个TCL列表
但是,它永远不会那么远,这是我得到的错误:
无法执行echo''<? if(@is_file(&.; ./ functions.inc.php")){
require_once(&.; ./ functions.inc.php"); echo xml_to_tcl_list("& lt;?xml
version =& quot; 1.0& quot; encod":文件名太长
我确信我会以错误的方式解决这个问题,但是我无法理解
正确的方式(TCL DOM解析远远超出我的理解能力,
我已阅读手册,教程,书籍,但无济于事:我根本不知道
了解TCL如何解析XML,我只懂简单的PHP
解析XML)
所以在这一点上,我想做的就是将XML字符串转换为TCL
列表,而且只有方式我知道怎么做是通过PHP,但我不能得到
三种语言合作。
帮助赞赏。
Thanx
Phil
fileID [文件大小
{fileName} .xml]];关闭
fileID
if {![string equal
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:
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 longI 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
解决方案fileID [file size
{fileName}.xml]]; close
fileID
if {![string equal
这篇关于TCL / PHP / XML问题:我需要将XML文件转换为TCL列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!