f



TCL/PHP/XML problem: I need to convert an XML file into a TCL list

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("&lt;?xml
version=&quot;1.0&quot; 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.

Help appreciated.

Thanx
Phil

0
11/25/2006 10:57:31 AM
comp.lang.php 32646 articles. 0 followers. Post Follow

49 Replies
1799 Views

Similar Articles

[PageSpeed] 23

comp.lang.tcl wrote:
>    set cannotRunPHP [catch {exec "echo '$php' | php" >@stdout
> 2>&stderr} errorMsg]

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

You can read a wiki page on the subject here: http://mini.net/tcl/exec
0
oakley (2075)
11/25/2006 3:54:12 PM
Bryan Oakley wrote:
> comp.lang.tcl wrote:
> >    set cannotRunPHP [catch {exec "echo '$php' | php" >@stdout
> > 2>&stderr} errorMsg]
>
> 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

0
11/25/2006 6:11:18 PM
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] {\&#034;}
> phpEscapedContents
>    regsub -all {"} $phpEscapedContents {\&quot;} 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("&lt;?xml
> version=&quot;1.0&quot; 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
0
schlenk (1615)
11/25/2006 6:27:18 PM
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] {\&#034;}
> > phpEscapedContents
> >    regsub -all {"} $phpEscapedContents {\&quot;} 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("&lt;?xml
> > version=&quot;1.0&quot; 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 &quot;Trilogy of Knowledge&quot;?"
answerID="1" correctAnswerID="1" answer="Believer"
expDate="1139634000"></entry><entry id="1102" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="2"
correctAnswerID="1" answer="Saviour Machine"
expDate="1139634000"></entry><entry id="1103" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="3"
correctAnswerID="1" answer="Seventh Avenue"
expDate="1139634000"></entry><entry id="1104" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="4"
correctAnswerID="1" answer="Inevitable End"
expDate="1139634000"></entry><entry id="1105" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="5"
correctAnswerID="1" answer="No such song existed"
expDate="1139634000"></entry>

Phil


> 
> Michael

0
11/25/2006 6:37:47 PM
comp.lang.tcl wrote:
> Bryan Oakley wrote:
> 
>>comp.lang.tcl wrote:
>>
>>>   set cannotRunPHP [catch {exec "echo '$php' | php" >@stdout
>>>2>&stderr} errorMsg]
>>
>>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!

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.

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'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.

0
oakley (2075)
11/25/2006 6:42:57 PM
Bryan Oakley wrote:
> comp.lang.tcl wrote:
> > Bryan Oakley wrote:
> >
> >>comp.lang.tcl wrote:
> >>
> >>>   set cannotRunPHP [catch {exec "echo '$php' | php" >@stdout
> >>>2>&stderr} errorMsg]
> >>
> >>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!
>
> 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 &quot;Trilogy of Knowledge&quot;?"
answerID="1" correctAnswerID="1" answer="Believer"
expDate="1139634000"></entry><entry id="1102" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="2"
correctAnswerID="1" answer="Saviour Machine"
expDate="1139634000"></entry><entry id="1103" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="3"
correctAnswerID="1" answer="Seventh Avenue"
expDate="1139634000"></entry><entry id="1104" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="4"
correctAnswerID="1" answer="Inevitable End"
expDate="1139634000"></entry><entry id="1105" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="5"
correctAnswerID="1" answer="No such song existed"
expDate="1139634000"></entry></trivia>

Into this:

id 1101 triviaID 233 question {Who wrote &quot;Trilogy of
Knowledge&quot;?} 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.

0
11/25/2006 6:53:21 PM
comp.lang.tcl wrote:
> ... 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 &quot;Trilogy of Knowledge&quot;?"
> answerID="1" correctAnswerID="1" answer="Believer"
> expDate="1139634000"></entry><entry id="1102" triviaID="233"
> question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="2"
> correctAnswerID="1" answer="Saviour Machine"
> expDate="1139634000"></entry><entry id="1103" triviaID="233"
> question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="3"
> correctAnswerID="1" answer="Seventh Avenue"
> expDate="1139634000"></entry><entry id="1104" triviaID="233"
> question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="4"
> correctAnswerID="1" answer="Inevitable End"
> expDate="1139634000"></entry><entry id="1105" triviaID="233"
> question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="5"
> correctAnswerID="1" answer="No such song existed"
> expDate="1139634000"></entry>

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

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 &quot;Trilogy of Knowledge&quot;?"
answerID="1" correctAnswerID="1" answer="Believer"
expDate="1139634000"></entry><entry id="1102" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="2"
correctAnswerID="1" answer="Saviour Machine"
expDate="1139634000"></entry><entry id="1103" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="3"
correctAnswerID="1" answer="Seventh Avenue"
expDate="1139634000"></entry><entry id="1104" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="4"
correctAnswerID="1" answer="Inevitable End"
expDate="1139634000"></entry><entry id="1105" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" 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:

     # 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:

trivia {} {{entry {id 1101 triviaID 233 question {Who wrote 
&quot;Trilogy of Knowledge&quot;?} answerID 1 correctAnswerID 1 answer 
Believer expDate 1139634000} {}} {entry {id 1102 triviaID 233 question 
{Who wrote &quot;Trilogy of Knowledge&quot;?} answerID 2 correctAnswerID 
1 answer {Saviour Machine} expDate 1139634000} {}} {entry {id 1103 
triviaID 233 question {Who wrote &quot;Trilogy of Knowledge&quot;?} 
answerID 3 correctAnswerID 1 answer {Seventh Avenue} expDate 1139634000} 
{}} {entry {id 1104 triviaID 233 question {Who wrote &quot;Trilogy of 
Knowledge&quot;?} answerID 4 correctAnswerID 1 answer {Inevitable End} 
expDate 1139634000} {}} {entry {id 1105 triviaID 233 question {Who wrote 
&quot;Trilogy of Knowledge&quot;?} 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 &quot; 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.
0
oakley (2075)
11/25/2006 7:04:57 PM
Bryan Oakley wrote:
> comp.lang.tcl wrote:
> > ... 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 &quot;Trilogy of Knowledge&quot;?"
> > answerID="1" correctAnswerID="1" answer="Believer"
> > expDate="1139634000"></entry><entry id="1102" triviaID="233"
> > question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="2"
> > correctAnswerID="1" answer="Saviour Machine"
> > expDate="1139634000"></entry><entry id="1103" triviaID="233"
> > question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="3"
> > correctAnswerID="1" answer="Seventh Avenue"
> > expDate="1139634000"></entry><entry id="1104" triviaID="233"
> > question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="4"
> > correctAnswerID="1" answer="Inevitable End"
> > expDate="1139634000"></entry><entry id="1105" triviaID="233"
> > question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="5"
> > correctAnswerID="1" answer="No such song existed"
> > expDate="1139634000"></entry>
>
> 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 &quot;Trilogy of Knowledge&quot;?"
> answerID="1" correctAnswerID="1" answer="Believer"
> expDate="1139634000"></entry><entry id="1102" triviaID="233"
> question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="2"
> correctAnswerID="1" answer="Saviour Machine"
> expDate="1139634000"></entry><entry id="1103" triviaID="233"
> question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="3"
> correctAnswerID="1" answer="Seventh Avenue"
> expDate="1139634000"></entry><entry id="1104" triviaID="233"
> question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="4"
> correctAnswerID="1" answer="Inevitable End"
> expDate="1139634000"></entry><entry id="1105" triviaID="233"
> question="Who wrote &quot;Trilogy of Knowledge&quot;?" 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
> &quot;Trilogy of Knowledge&quot;?} answerID 1 correctAnswerID 1 answer
> Believer expDate 1139634000} {}} {entry {id 1102 triviaID 233 question
> {Who wrote &quot;Trilogy of Knowledge&quot;?} answerID 2 correctAnswerID
> 1 answer {Saviour Machine} expDate 1139634000} {}} {entry {id 1103
> triviaID 233 question {Who wrote &quot;Trilogy of Knowledge&quot;?}
> answerID 3 correctAnswerID 1 answer {Seventh Avenue} expDate 1139634000}
> {}} {entry {id 1104 triviaID 233 question {Who wrote &quot;Trilogy of
> Knowledge&quot;?} answerID 4 correctAnswerID 1 answer {Inevitable End}
> expDate 1139634000} {}} {entry {id 1105 triviaID 233 question {Who wrote
> &quot;Trilogy of Knowledge&quot;?} 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 &quot; 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

0
11/25/2006 7:15:12 PM
comp.lang.tcl wrote:
> Bryan Oakley wrote:
>>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]
> 

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.

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.


0
oakley (2075)
11/25/2006 7:31:18 PM
Bryan Oakley wrote:
> comp.lang.tcl wrote:
> > Bryan Oakley wrote:
> >>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]
> >
>
> 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 &quot;Trilogy of Knowledge&quot;?"
answerID="1" correctAnswerID="1" answer="Believer"
expDate="1139634000"></entry><entry id="1102" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="2"
correctAnswerID="1" answer="Saviour Machine"
expDate="1139634000"></entry><entry id="1103" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="3"
correctAnswerID="1" answer="Seventh Avenue"
expDate="1139634000"></entry><entry id="1104" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="4"
correctAnswerID="1" answer="Inevitable End"
expDate="1139634000"></entry><entry id="1105" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" 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.

0
11/25/2006 7:40:03 PM
In article <tt0ah.6413$yf7.3870@newssvr21.news.prodigy.net>,
Bryan Oakley  <oakley@bardo.clearlight.com> wrote:
			.
			.
			.
>     # add a trailing </trivia> which is missing from
>     # the sample data
>     set data "$data</trivia>"
			.
			.
			.
Alternatively, as Bryan knows, but doubtless eschewed for
pedagogic reasons,

  append data </trivia>
0
claird (2363)
11/25/2006 7:40:41 PM
comp.lang.tcl wrote:
> id 1101 triviaID 233 question {Who wrote &quot;Trilogy of
> Knowledge&quot;?} answerID 1 correctAnswerID 1 answer Believer expDate
> 113963500

Take the zip file I posted. Install it. Call

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."
0
dnew (1159)
11/25/2006 7:45:47 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="&quot;In that day&quot; says the Lord, &quot;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.&quot;"></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
&quot;satanists&quot;" phrase="&quot;..the serpent was created by a god
that doesn't exist..&quot;.. Oh, so Satan doesn't exist
either??!!"></saying><saying id="18" author="Matt's interpretation of
&quot;Screams of Abel&quot;" 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="&quot;Thank you, please!&quot;"></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 &quot;Dune&quot;
(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

0
11/25/2006 7:49:46 PM
Darren New wrote:
> comp.lang.tcl wrote:
> > id 1101 triviaID 233 question {Who wrote &quot;Trilogy of
> > Knowledge&quot;?} answerID 1 correctAnswerID 1 answer Believer expDate
> > 113963500
>
> 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."

0
11/25/2006 7:50:55 PM
Cameron Laird wrote:
> In article <tt0ah.6413$yf7.3870@newssvr21.news.prodigy.net>,
> Bryan Oakley  <oakley@bardo.clearlight.com> wrote:
> 			.
> 			.
> 			.
> >     # add a trailing </trivia> which is missing from
> >     # the sample data
> >     set data "$data</trivia>"
> 			.
> 			.
> 			.
> 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!

0
11/25/2006 8:08:09 PM
comp.lang.tcl wrote:
> ...
> produces the correct list results, but why? Why is this fails then:

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.
0
oakley (2075)
11/25/2006 8:15:27 PM
Bryan Oakley wrote:
> comp.lang.tcl wrote:
> > ...
> > produces the correct list results, but why? Why is this fails then:
>
> 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

0
11/25/2006 8:22:00 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 &quot;Trilogy 
of Knowledge&quot;?" answerID="1" correctAnswerID="1" answer="Believer" 
expDate="1139634000"></entry>
         <entry id="1102" triviaID="233" question="Who wrote &quot;Trilogy 
of Knowledge&quot;?" answerID="2" correctAnswerID="1" answer="Saviour 
Machine" expDate="1139634000"> </entry>
         <entry id="1103" triviaID="233" question="Who wrote &quot;Trilogy 
of Knowledge&quot;?" answerID="3" correctAnswerID="1" answer="Seventh 
Avenue" expDate="1139634000"></entry>
         <entry id="1104" triviaID="233" question="Who wrote &quot;Trilogy 
of Knowledge&quot;?" answerID="4" correctAnswerID="1" answer="Inevitable 
End" expDate="1139634000"></entry>
         <entry id="1105" triviaID="233" question="Who wrote &quot;Trilogy 
of Knowledge&quot;?" 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|
+------------------------------------------------------------------------+
0
Gerald.Lester (2014)
11/25/2006 8:34:00 PM
Gerald W. Lester wrote:
> 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

Sorry I am unable to figure out how to install and use tdom.  I tried
this

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

at the top of xml_procs.tcl, to no avail, I get the following error:

can't find package tdom while executing "package require tdom" (file
"xml_procs.tcl" line 2)

I was able to download and install tdom, or I guess install it:

1) I downloaded it

2) I unzipped it

3) everything's in /home/ppowell/web/cgi-bin/tDom-0.8.0

4) I was not allowed to do ../configure, much less "make" nor "make
install", "../configure" not found

Phil

>
> set xml {<?xml version="1.0" encoding="utf-8" ?>
>      <trivia>
>          <entry id="1101" triviaID="233" question="Who wrote &quot;Trilogy
> of Knowledge&quot;?" answerID="1" correctAnswerID="1" answer="Believer"
> expDate="1139634000"></entry>
>          <entry id="1102" triviaID="233" question="Who wrote &quot;Trilogy
> of Knowledge&quot;?" answerID="2" correctAnswerID="1" answer="Saviour
> Machine" expDate="1139634000"> </entry>
>          <entry id="1103" triviaID="233" question="Who wrote &quot;Trilogy
> of Knowledge&quot;?" answerID="3" correctAnswerID="1" answer="Seventh
> Avenue" expDate="1139634000"></entry>
>          <entry id="1104" triviaID="233" question="Who wrote &quot;Trilogy
> of Knowledge&quot;?" answerID="4" correctAnswerID="1" answer="Inevitable
> End" expDate="1139634000"></entry>
>          <entry id="1105" triviaID="233" question="Who wrote &quot;Trilogy
> of Knowledge&quot;?" 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|
> +------------------------------------------------------------------------+

0
11/25/2006 11:39:31 PM
CORRECTION:

Now I get this:

couldn't read file "/home/ppowell/web/cgi-bin/tDOM-0.8.0/win/tdom.tcl":
no such file or directory while executing "source
/home/ppowell/web/cgi-bin/tDOM-0.8.0/win/tdom.tcl" ("package ifneeded"
script) invoked from within "package require tdom" (file
"xml_procs.tcl" line 2)

When I try this:

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

comp.lang.tcl wrote:
> Gerald W. Lester wrote:
> > 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
>
> Sorry I am unable to figure out how to install and use tdom.  I tried
> this
>
> lappend auto_path /home/ppowell/web/cgi-bin
> package require tdom
>
> at the top of xml_procs.tcl, to no avail, I get the following error:
>
> can't find package tdom while executing "package require tdom" (file
> "xml_procs.tcl" line 2)
>
> I was able to download and install tdom, or I guess install it:
>
> 1) I downloaded it
>
> 2) I unzipped it
>
> 3) everything's in /home/ppowell/web/cgi-bin/tDom-0.8.0
>
> 4) I was not allowed to do ../configure, much less "make" nor "make
> install", "../configure" not found
>
> Phil
>
> >
> > set xml {<?xml version="1.0" encoding="utf-8" ?>
> >      <trivia>
> >          <entry id="1101" triviaID="233" question="Who wrote &quot;Trilogy
> > of Knowledge&quot;?" answerID="1" correctAnswerID="1" answer="Believer"
> > expDate="1139634000"></entry>
> >          <entry id="1102" triviaID="233" question="Who wrote &quot;Trilogy
> > of Knowledge&quot;?" answerID="2" correctAnswerID="1" answer="Saviour
> > Machine" expDate="1139634000"> </entry>
> >          <entry id="1103" triviaID="233" question="Who wrote &quot;Trilogy
> > of Knowledge&quot;?" answerID="3" correctAnswerID="1" answer="Seventh
> > Avenue" expDate="1139634000"></entry>
> >          <entry id="1104" triviaID="233" question="Who wrote &quot;Trilogy
> > of Knowledge&quot;?" answerID="4" correctAnswerID="1" answer="Inevitable
> > End" expDate="1139634000"></entry>
> >          <entry id="1105" triviaID="233" question="Who wrote &quot;Trilogy
> > of Knowledge&quot;?" 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|
> > +------------------------------------------------------------------------+

0
11/25/2006 11:48:57 PM

On Nov 26, 12:39 am, "comp.lang.tcl" <phillip.s.pow...@gmail.com>
wrote:
> Gerald W. Lester wrote:
> > 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 tdomSorry I am unable to figure out how to install and use tdom.  I tried
> this
>
> lappend auto_path /home/ppowell/web/cgi-bin
> package require tdom
>
> at the top of xml_procs.tcl, to no avail, I get the following error:
>
> can't find package tdom while executing "package require tdom" (file
> "xml_procs.tcl" line 2)
>
> I was able to download and install tdom, or I guess install it:
>
> 1) I downloaded it
>
> 2) I unzipped it
>
> 3) everything's in /home/ppowell/web/cgi-bin/tDom-0.8.0
>
> 4) I was not allowed to do ../configure, much less "make" nor "make
> install", "../configure" not found
>

You downloaded the source version and are not allowed to compile it.
Try this instead.:

1) Download http://marknet.tk/downloads/tdom.zip
2) unzip the zip in /home/ppowell/web/cgi-bin/tDom-0.8.0 the zip
contains a binary for tdom for linux
3) Try your script again

Hope that works. I couldn't test it (I am on windows)

Mark

0
mpc.janssen (384)
11/25/2006 11:56:12 PM
Mark Janssen wrote:
> On Nov 26, 12:39 am, "comp.lang.tcl" <phillip.s.pow...@gmail.com>
> wrote:
> > Gerald W. Lester wrote:
> > > 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 tdomSorry I am unable to figure out how to install and use tdom.  I tried
> > this
> >
> > lappend auto_path /home/ppowell/web/cgi-bin
> > package require tdom
> >
> > at the top of xml_procs.tcl, to no avail, I get the following error:
> >
> > can't find package tdom while executing "package require tdom" (file
> > "xml_procs.tcl" line 2)
> >
> > I was able to download and install tdom, or I guess install it:
> >
> > 1) I downloaded it
> >
> > 2) I unzipped it
> >
> > 3) everything's in /home/ppowell/web/cgi-bin/tDom-0.8.0
> >
> > 4) I was not allowed to do ../configure, much less "make" nor "make
> > install", "../configure" not found
> >
>
> You downloaded the source version and are not allowed to compile it.
> Try this instead.:
>
> 1) Download http://marknet.tk/downloads/tdom.zip
> 2) unzip the zip in /home/ppowell/web/cgi-bin/tDom-0.8.0 the zip
> contains a binary for tdom for linux
> 3) Try your script again
>
> Hope that works. I couldn't test it (I am on windows)

I may never find out, /cgi-bin was completely wiped out as a result.

Phil

> 
> Mark

0
11/25/2006 11:58:11 PM
comp.lang.tcl wrote:
> Mark Janssen wrote:
> > On Nov 26, 12:39 am, "comp.lang.tcl" <phillip.s.pow...@gmail.com>
> > wrote:
> > > Gerald W. Lester wrote:
> > > > 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 tdomSorry I am unable to figure out how to install and use tdom.  I tried
> > > this
> > >
> > > lappend auto_path /home/ppowell/web/cgi-bin
> > > package require tdom
> > >
> > > at the top of xml_procs.tcl, to no avail, I get the following error:
> > >
> > > can't find package tdom while executing "package require tdom" (file
> > > "xml_procs.tcl" line 2)
> > >
> > > I was able to download and install tdom, or I guess install it:
> > >
> > > 1) I downloaded it
> > >
> > > 2) I unzipped it
> > >
> > > 3) everything's in /home/ppowell/web/cgi-bin/tDom-0.8.0
> > >
> > > 4) I was not allowed to do ../configure, much less "make" nor "make
> > > install", "../configure" not found
> > >
> >
> > You downloaded the source version and are not allowed to compile it.
> > Try this instead.:
> >
> > 1) Download http://marknet.tk/downloads/tdom.zip
> > 2) unzip the zip in /home/ppowell/web/cgi-bin/tDom-0.8.0 the zip
> > contains a binary for tdom for linux
> > 3) Try your script again
> >
> > Hope that works. I couldn't test it (I am on windows)
>
> I may never find out, /cgi-bin was completely wiped out as a result.

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 :(

Phil
> 
> Phil
> 
> > 
> > Mark

0
11/26/2006 12:21:55 AM
comp.lang.tcl wrote:
> comp.lang.tcl wrote:
>> Mark Janssen wrote:
>>> On Nov 26, 12:39 am, "comp.lang.tcl" <phillip.s.pow...@gmail.com>
>>> wrote:
>>>> Gerald W. Lester wrote:
>>>>> 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 tdomSorry I am unable to figure out how to install and use tdom.  I tried
>>>> this
>>>>
>>>> lappend auto_path /home/ppowell/web/cgi-bin
>>>> package require tdom
>>>>
>>>> at the top of xml_procs.tcl, to no avail, I get the following error:
>>>>
>>>> can't find package tdom while executing "package require tdom" (file
>>>> "xml_procs.tcl" line 2)
>>>>
>>>> I was able to download and install tdom, or I guess install it:
>>>>
>>>> 1) I downloaded it
>>>>
>>>> 2) I unzipped it
>>>>
>>>> 3) everything's in /home/ppowell/web/cgi-bin/tDom-0.8.0
>>>>
>>>> 4) I was not allowed to do ../configure, much less "make" nor "make
>>>> install", "../configure" not found
>>>>
>>> You downloaded the source version and are not allowed to compile it.
>>> Try this instead.:
>>>
>>> 1) Download http://marknet.tk/downloads/tdom.zip
>>> 2) unzip the zip in /home/ppowell/web/cgi-bin/tDom-0.8.0 the zip
>>> contains a binary for tdom for linux

He is on FreeBSD, he needs a build for that OS not linux.

>>> 3) Try your script again
>>>
>>> Hope that works. I couldn't test it (I am on windows)
>> I may never find out, /cgi-bin was completely wiped out as a result.
> 
> 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
>> Phil
>>
>>> Mark
> 


-- 
+--------------------------------+---------------------------------------+
| Gerald W. Lester                                                       |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
0
Gerald.Lester (2014)
11/26/2006 1:11:50 AM

On Nov 26, 2:11 am, "Gerald W. Lester" <Gerald.Les...@cox.net> wrote:
> comp.lang.tcl wrote:
> > comp.lang.tcl wrote:
> >> Mark Janssen wrote:
> >>> On Nov 26, 12:39 am, "comp.lang.tcl" <phillip.s.pow...@gmail.com>
> >>> wrote:
> >>>> Gerald W. Lester wrote:
> >>>>> 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 tdomSorry I am unable to figure out how to install and use tdom.  I tried
> >>>> this
>
> >>>> lappend auto_path /home/ppowell/web/cgi-bin
> >>>> package require tdom
>
> >>>> at the top of xml_procs.tcl, to no avail, I get the following error:
>
> >>>> can't find package tdom while executing "package require tdom" (file
> >>>> "xml_procs.tcl" line 2)
>
> >>>> I was able to download and install tdom, or I guess install it:
>
> >>>> 1) I downloaded it
>
> >>>> 2) I unzipped it
>
> >>>> 3) everything's in /home/ppowell/web/cgi-bin/tDom-0.8.0
>
> >>>> 4) I was not allowed to do ../configure, much less "make" nor "make
> >>>> install", "../configure" not found
>
> >>> You downloaded the source version and are not allowed to compile it.
> >>> Try this instead.:
>
> >>> 1) Downloadhttp://marknet.tk/downloads/tdom.zip
> >>> 2) unzip the zip in /home/ppowell/web/cgi-bin/tDom-0.8.0 the zip
> >>> contains a binary for tdom for linuxHe is on FreeBSD, he needs a build for that OS not linux.
>
> >>> 3) Try your script again
>
> >>> Hope that works. I couldn't test it (I am on windows)
> >> I may never find out, /cgi-bin was completely wiped out as a result.
>
> > 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.comso 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.
>
> 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

0
mpc.janssen (384)
11/26/2006 1:22:11 AM
Mark Janssen wrote:
> On Nov 26, 2:11 am, "Gerald W. Lester" <Gerald.Les...@cox.net> wrote:
> > comp.lang.tcl wrote:
> > > comp.lang.tcl wrote:
> > >> Mark Janssen wrote:
> > >>> On Nov 26, 12:39 am, "comp.lang.tcl" <phillip.s.pow...@gmail.com>
> > >>> wrote:
> > >>>> Gerald W. Lester wrote:
> > >>>>> 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 tdomSorry I am unable to figure out how to install and use tdom.  I tried
> > >>>> this
> >
> > >>>> lappend auto_path /home/ppowell/web/cgi-bin
> > >>>> package require tdom
> >
> > >>>> at the top of xml_procs.tcl, to no avail, I get the following error:
> >
> > >>>> can't find package tdom while executing "package require tdom" (file
> > >>>> "xml_procs.tcl" line 2)
> >
> > >>>> I was able to download and install tdom, or I guess install it:
> >
> > >>>> 1) I downloaded it
> >
> > >>>> 2) I unzipped it
> >
> > >>>> 3) everything's in /home/ppowell/web/cgi-bin/tDom-0.8.0
> >
> > >>>> 4) I was not allowed to do ../configure, much less "make" nor "make
> > >>>> install", "../configure" not found
> >
> > >>> You downloaded the source version and are not allowed to compile it.
> > >>> Try this instead.:
> >
> > >>> 1) Downloadhttp://marknet.tk/downloads/tdom.zip
> > >>> 2) unzip the zip in /home/ppowell/web/cgi-bin/tDom-0.8.0 the zip
> > >>> contains a binary for tdom for linuxHe is on FreeBSD, he needs a build for that OS not linux.
> >
> > >>> 3) Try your script again
> >
> > >>> Hope that works. I couldn't test it (I am on windows)
> > >> I may never find out, /cgi-bin was completely wiped out as a result.
> >
> > > 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.comso 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.
> >
> > 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.


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

0
11/26/2006 1:30:07 AM
Mark Janssen wrote:
> On Nov 26, 2:11 am, "Gerald W. Lester" <Gerald.Les...@cox.net> wrote:
> > comp.lang.tcl wrote:
> > > comp.lang.tcl wrote:
> > >> Mark Janssen wrote:
> > >>> On Nov 26, 12:39 am, "comp.lang.tcl" <phillip.s.pow...@gmail.com>
> > >>> wrote:
> > >>>> Gerald W. Lester wrote:
> > >>>>> 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 tdomSorry I am unable to figure out how to install and use tdom.  I tried
> > >>>> this
> >
> > >>>> lappend auto_path /home/ppowell/web/cgi-bin
> > >>>> package require tdom
> >
> > >>>> at the top of xml_procs.tcl, to no avail, I get the following error:
> >
> > >>>> can't find package tdom while executing "package require tdom" (file
> > >>>> "xml_procs.tcl" line 2)
> >
> > >>>> I was able to download and install tdom, or I guess install it:
> >
> > >>>> 1) I downloaded it
> >
> > >>>> 2) I unzipped it
> >
> > >>>> 3) everything's in /home/ppowell/web/cgi-bin/tDom-0.8.0
> >
> > >>>> 4) I was not allowed to do ../configure, much less "make" nor "make
> > >>>> install", "../configure" not found
> >
> > >>> You downloaded the source version and are not allowed to compile it.
> > >>> Try this instead.:
> >
> > >>> 1) Downloadhttp://marknet.tk/downloads/tdom.zip
> > >>> 2) unzip the zip in /home/ppowell/web/cgi-bin/tDom-0.8.0 the zip
> > >>> contains a binary for tdom for linuxHe is on FreeBSD, he needs a build for that OS not linux.
> >
> > >>> 3) Try your script again
> >
> > >>> Hope that works. I couldn't test it (I am on windows)
> > >> I may never find out, /cgi-bin was completely wiped out as a result.
> >
> > > 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.comso 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.
> >
> > 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

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

0
11/26/2006 1:54:26 AM

On Nov 26, 2:54 am, "comp.lang.tcl" <phillip.s.pow...@gmail.com> wrote:
> Mark Janssen wrote:
> > On Nov 26, 2:11 am, "Gerald W. Lester" <Gerald.Les...@cox.net> wrote:
> > > comp.lang.tcl wrote:
> > > > comp.lang.tcl wrote:
> > > >> Mark Janssen wrote:
> > > >>> On Nov 26, 12:39 am, "comp.lang.tcl" <phillip.s.pow...@gmail.com>
> > > >>> wrote:
> > > >>>> Gerald W. Lester wrote:
> > > >>>>> 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 tdomSorry I am unable to figure out how to install and use tdom.  I tried
> > > >>>> this
>
> > > >>>> lappend auto_path /home/ppowell/web/cgi-bin
> > > >>>> package require tdom
>
> > > >>>> at the top of xml_procs.tcl, to no avail, I get the following error:
>
> > > >>>> can't find package tdom while executing "package require tdom" (file
> > > >>>> "xml_procs.tcl" line 2)
>
> > > >>>> I was able to download and install tdom, or I guess install it:
>
> > > >>>> 1) I downloaded it
>
> > > >>>> 2) I unzipped it
>
> > > >>>> 3) everything's in /home/ppowell/web/cgi-bin/tDom-0.8.0
>
> > > >>>> 4) I was not allowed to do ../configure, much less "make" nor "make
> > > >>>> install", "../configure" not found
>
> > > >>> You downloaded the source version and are not allowed to compile it.
> > > >>> Try this instead.:
>
> > > >>> 1) Downloadhttp://marknet.tk/downloads/tdom.zip
> > > >>> 2) unzip the zip in /home/ppowell/web/cgi-bin/tDom-0.8.0 the zip
> > > >>> contains a binary for tdom for linuxHe is on FreeBSD, he needs a build for that OS not linux.
>
> > > >>> 3) Try your script again
>
> > > >>> Hope that works. I couldn't test it (I am on windows)
> > > >> I may never find out, /cgi-bin was completely wiped out as a result.
>
> > > > 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.comsoI 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.
>
> > > 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**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:

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

0
mpc.janssen (384)
11/26/2006 2:14:58 AM
Mark Janssen wrote:
> 
>> /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")

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|
+------------------------------------------------------------------------+
0
Gerald.Lester (2014)
11/26/2006 2:57:29 AM
Gerald W. Lester wrote:
> Mark Janssen wrote:
> >
> >> /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")
>
> 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|
> +------------------------------------------------------------------------+

0
11/26/2006 3:08:10 AM
comp.lang.tcl wrote:
> Gerald W. Lester wrote:
>> Mark Janssen wrote:
>>>> /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")
>> 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?

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|
+------------------------------------------------------------------------+
0
Gerald.Lester (2014)
11/26/2006 3:22:56 AM
Gerald W. Lester wrote:
> comp.lang.tcl wrote:
> > Gerald W. Lester wrote:
> >> Mark Janssen wrote:
> >>>> /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")
> >> 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?
>
> 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|
> +------------------------------------------------------------------------+

0
11/26/2006 4:06:14 AM
comp.lang.tcl wrote:
> Gerald W. Lester wrote:
>> comp.lang.tcl wrote:
>>> Gerald W. Lester wrote:
>>>> Mark Janssen wrote:
>>>>>> /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")
>>>> 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?
>> 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

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|
+------------------------------------------------------------------------+
0
Gerald.Lester (2014)
11/26/2006 4:18:29 AM

  package require tdom

  set doc [dom parse {<?xml version="1.0" encoding="utf-8" ?><trivia><entry  
id="1101"
triviaID="233" question="Who wrote &quot;Trilogy of Knowledge&quot;?"
answerID="1" correctAnswerID="1" answer="Believer"
expDate="1139634000"></entry><entry id="1102" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="2"
correctAnswerID="1" answer="Saviour Machine"
expDate="1139634000"></entry><entry id="1103" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="3"
correctAnswerID="1" answer="Seventh Avenue"
expDate="1139634000"></entry><entry id="1104" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="4"
correctAnswerID="1" answer="Inevitable End"
expDate="1139634000"></entry><entry id="1105" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" 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 &quot;Trilogy of Knowledge&quot;?"
answerID="1" correctAnswerID="1" answer="Believer"
expDate="1139634000"></entry><entry id="1102" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="2"
correctAnswerID="1" answer="Saviour Machine"
expDate="1139634000"></entry><entry id="1103" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="3"
correctAnswerID="1" answer="Seventh Avenue"
expDate="1139634000"></entry><entry id="1104" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="4"
correctAnswerID="1" answer="Inevitable End"
expDate="1139634000"></entry><entry id="1105" triviaID="233"
question="Who wrote &quot;Trilogy of Knowledge&quot;?" answerID="5"
correctAnswerID="1" answer="No such song existed"
expDate="1139634000"></entry></trivia>

Into this:
0
ramsan (89)
11/26/2006 10:30:57 AM
> 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 &quot;Trilogy of Knowledge&quot;?"
> 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 &quot;Trilogy of
> Knowledge&quot;?} 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

0
Steve.Ball (89)
11/26/2006 9:04:23 PM
Gerald W. Lester wrote:
> comp.lang.tcl wrote:
> > Gerald W. Lester wrote:
> >> comp.lang.tcl wrote:
> >>> Gerald W. Lester wrote:
> >>>> Mark Janssen wrote:
> >>>>>> /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")
> >>>> 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?
> >> 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
>
> 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|
> +------------------------------------------------------------------------+

0
11/27/2006 4:54:10 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

0
11/27/2006 5:16:51 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 cool thanx I will try that!
Phil

0
11/27/2006 6:07:05 PM
In article <1164575063.770613.309370@l12g2000cwl.googlegroups.com>,
Steve Ball <Steve.Ball@explain.com.au> wrote:
			.
			.
			.
>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 &quot;Trilogy of
>> Knowledge&quot;?} 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.
I think this part VERY MUCH deserves repetition.
It is indeed ... silly to serialize relational
data into XML on the way to Tcl.
			.
			.
			.
>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.
I'm all in favor of dicts.

I don't understand the comment about threading.
How is concurrency an issue at all?
			.
			.
			.
0
claird (2363)
11/27/2006 9:04:02 PM
In article <1164575063.770613.309370@l12g2000cwl.googlegroups.com>,
Steve Ball <Steve.Ball@explain.com.au> wrote:
			.
			.
			.
>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
			.
			.
			.
Phil says <URL:
http://groups.google.com/group/comp.lang.tcl/msg/6b0f6e6f9cf41e39 >
that, were this PHP, he'd write

  $parser = @xml_parser_create();
  @xml_parser_set_options($parser, XML_OPTION_SKIP_WHITE, true);
  @xml_parse_into_struct($parser, $xml, $xmlArray, $tags);
  @xml_parser_free($parser);

This certainly compares favorably in concision to Steve's solution.

It's comparison that deserves a bit more explanation, though.  First,
unless Phil is running a non-standard installation, the second line
needs to be

  @xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, true);

Also, the result puts essentially an entire DOM tree in $xmlArray;
my guess is that Phil assumes dereferencing of the [attributes] of
the [VIA] node(s).  The PHP program above, though, does NOT make a
list of all attributes of all tags, as Steve and others of us read
the problem.

I don't have any particular conclusion.  For those thinking DOM
and Tcl and SAX are complicated, I recommend study of <URL:
http://www.php.net/manual/en/function.xml-parse-into-struct.php >:
"This function parses an XML file into 2 parallel array structures
...."  In any case, the simple PHP script gives the promised results
only with extra assumptions.
0
claird (2363)
11/27/2006 9:32:02 PM
Cameron Laird wrote:
> In article <1164575063.770613.309370@l12g2000cwl.googlegroups.com>,
> Steve Ball <Steve.Ball@explain.com.au> wrote:
> 			.
> 			.
> 			.
> >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 &quot;Trilogy of
> >> Knowledge&quot;?} 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.
> I think this part VERY MUCH deserves repetition.
> It is indeed ... silly to serialize relational
> data into XML on the way to Tcl.
> 			.
> 			.
> 			.
> >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.
> 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?
> 			.
> 			.
> 			.

0
11/27/2006 9:38:35 PM
comp.lang.tcl wrote:
> 
> 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?

The one thing CSV has over XML is a greatly (*greatly*) reduced learning 
curve, and a readily available pure tcl tool for parsing it. (CSV stands 
for Comma Separated Values and is just like what it sounds)

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

Consider CSV to be a dixie-cup compared to the firehose that is XML.

For that matter, though, if you control the data you might want to 
consider storing the data as a Tcl list in the first place. Then you 
don't have to parse it at all.
0
oakley (2075)
11/27/2006 9:48:33 PM
In article <1164663514.879941.235380@f16g2000cwb.googlegroups.com>,
comp.lang.tcl <phillip.s.powell@gmail.com> wrote:
			.
			.
			.
>Dicts? What is a dict? Again I don't know your terminology
			.
			.
			.
>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.
			.
			.
			.
XML's fine by me.

What's left to do?  Michael, Bryan, and Steve have all given 
what look to me to be quite nice solutions to the problem
you expressed, and I just posted what I believe is the 
shortest one yet.  Is there any barrier still standing between
you and the XML parsing you're after?

I'm sympathetic to cultural differences.  I find it very
frustrating to read the abbreviations that are common with an
in-group.  The clt community is NOT limited to "very
seasoned engineers", though, I can assure you.  From all I can
tell, we're not the ones spraying a firehose; we keep trying 
to find one specific symptom on which we can focus.

If you can [package require tdom], you're only a few lines
away from the solution you have written you're after.

I'm narrowing follow-ups.
0
claird (2363)
11/27/2006 10:32:42 PM
In article <1164485289.600387.306210@l12g2000cwl.googlegroups.com>,
comp.lang.tcl <phillip.s.powell@gmail.com> wrote:
>
>Cameron Laird wrote:
>> In article <tt0ah.6413$yf7.3870@newssvr21.news.prodigy.net>,
>> Bryan Oakley  <oakley@bardo.clearlight.com> wrote:
>> 			.
>> 			.
>> 			.
>> >     # add a trailing </trivia> which is missing from
>> >     # the sample data
>> >     set data "$data</trivia>"
>> 			.
>> 			.
>> 			.
>> 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!
>

I don't understand your question.

Bryan's recommendation included the line

    set data "$data</trivia>"

I suspect some readers will want to know that 

    append data </trivia>

is valid Tcl which produces almost exactly the
same result.
0
claird (2363)
11/27/2006 10:37:48 PM
In article <1164500515.137824.215250@f16g2000cwb.googlegroups.com>,
comp.lang.tcl <phillip.s.powell@gmail.com> wrote:
			.
			.
			.
>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
			.
			.
			.
You can achieve the result you've written without tDOM.
I'd be curious to learn, though, how tDOM is incompatible
with www.clearlight.com.  Maybe there's a misunderstanding,
and tDOM is more available to you than you realize.
0
claird (2363)
11/27/2006 10:40:28 PM
Bryan Oakley wrote:
> comp.lang.tcl wrote:
> >
> > 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?
>
> The one thing CSV has over XML is a greatly (*greatly*) reduced learning
> curve, and a readily available pure tcl tool for parsing it. (CSV stands
> for Comma Separated Values and is just like what it sounds)
>
> > 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!
>
> Consider CSV to be a dixie-cup compared to the firehose that is XML.
>
> For that matter, though, if you control the data you might want to
> consider storing the data as a Tcl list in the first place. Then you
> don't have to parse it at all.

I'm not sure how you can store a TCL list as a flat file, please show
me how that would be done.

I'm beginning to think I should stop posting here only because I'm
feeling more and more comparatively dumb here :(

Phil

0
11/27/2006 10:59:23 PM
comp.lang.tcl wrote:
> Bryan Oakley wrote:
>> comp.lang.tcl wrote:
>>> 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?
>> The one thing CSV has over XML is a greatly (*greatly*) reduced learning
>> curve, and a readily available pure tcl tool for parsing it. (CSV stands
>> for Comma Separated Values and is just like what it sounds)
>>
>>> 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!
>> Consider CSV to be a dixie-cup compared to the firehose that is XML.
>>
>> For that matter, though, if you control the data you might want to
>> consider storing the data as a Tcl list in the first place. Then you
>> don't have to parse it at all.
> 
> I'm not sure how you can store a TCL list as a flat file, please show
> me how that would be done.

There's no magic. Remember, a tcl list can be represented a string, so 
you save it to a file the way you would any string:

     set f [open somefile w]
     puts $f $tclList
     close $f

That puts a tcl list on disk. You can then read it back with this:

     set f [open somefile r]
     set tclList [read $f]
     close $f

What is in $tclList after reading the file is a string representation of 
the list, which can be treated as a bona fide list.

Note, you should *not* do this if other processes or people can edit the 
file. If there's any chance something could alter the data by, say, 
removing or adding curly braces or quotes where they don't belong, you 
can't assume what you read in will be a valid list. This technique only 
works when you have complete control over the data.


0
oakley (2075)
11/27/2006 11:21:42 PM
In article <1164668363.169502.82260@l12g2000cwl.googlegroups.com>,
comp.lang.tcl <phillip.s.powell@gmail.com> wrote:
			.
			.
			.
>I'm not sure how you can store a TCL list as a flat file, please show
>me how that would be done.
			.
			.
			.
<URL: http://wiki.tcl.tk/15296 >
0
claird (2363)
11/27/2006 11:44:53 PM
Bryan Oakley wrote:
> comp.lang.tcl wrote:
> > Bryan Oakley wrote:
> >> comp.lang.tcl wrote:
> >>> 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?
> >> The one thing CSV has over XML is a greatly (*greatly*) reduced learning
> >> curve, and a readily available pure tcl tool for parsing it. (CSV stands
> >> for Comma Separated Values and is just like what it sounds)
> >>
> >>> 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!
> >> Consider CSV to be a dixie-cup compared to the firehose that is XML.
> >>
> >> For that matter, though, if you control the data you might want to
> >> consider storing the data as a Tcl list in the first place. Then you
> >> don't have to parse it at all.
> >
> > I'm not sure how you can store a TCL list as a flat file, please show
> > me how that would be done.
>
> There's no magic. Remember, a tcl list can be represented a string, so
> you save it to a file the way you would any string:
>
>      set f [open somefile w]
>      puts $f $tclList
>      close $f
>
> That puts a tcl list on disk. You can then read it back with this:
>
>      set f [open somefile r]
>      set tclList [read $f]
>      close $f
>
> What is in $tclList after reading the file is a string representation of
> the list, which can be treated as a bona fide list.
>
> Note, you should *not* do this if other processes or people can edit the
> file. If there's any chance something could alter the data by, say,
> removing or adding curly braces or quotes where they don't belong, you
> can't assume what you read in will be a valid list. This technique only
> works when you have complete control over the data.

Thanx, going forward I will try to remember that.  I appreciate
everyone's help (and patience), looks like I got most of the site
fixed, except for one part that I converted to PHP from Tcl (sorry
guys)

Phil

0
11/28/2006 7:35:57 AM
Reply:

Similar Artilces:

problem when outputting an xml file using php
Hi there, I am trying to output a file, coutries.xml, which is in the following format: <xml... <countries> <country id="1">Afghanistan</country> <country id="2">Albania</country> . . . <country id="194">Zimbabwe</country> </countries> The PHP code I am using is: $xml_document = domxml_open_file('xml/countries.xml'); if ($xml_document) { $items = $xml_document->get_elements_by_tagname('country'); $count = count($items); for ($i = 0; $i < $count; $i++) { $item = ...

OpenVMS + PHP +XSL + DOM XML problem --> (cannot load/transform XML)
Hey! I have a problem loading (transforming) XML file using DOM XML extension on OpenVMS (alpha). I have installed libxml2, mysql, apache,... following steps described here (http://www.pi-net.dyndns.org/anonymous/kits/) All I want to do is: 1. build an XML from MySQL DB (functions like load, saveXML, appendChild, createElement are used) 2. Load an XSL file 3. transform XML with loaded XSL and show (echo) the result of the transformation My problem is that none of xmldom functions (which work on PHP 5) are supported. Why is that? Do I need some extension for domxml for OpenVMS? Where...

converting xml file to schema file problem
i am converting a xml file having namespaces in to schema file (.xsd) for validation. my xml file is test.xml ----------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <root xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:h="http://www.w3.org/TR/html4/" xmlns:f="http://www.w3.org/TR/scxml/"> <h:table> <h:tr>vegitables</h:tr> <h:td>Apples</h:td> </h:table> <f:table> <f:name>African Coffee Table</f:name> <f:data>hari</f:data> <f:length>oum</f:length> </f:table> </root> ---------------------------------------------------------- I converted this xml file in to schema file. test.xsd ---------------------------------------------------------- <?xml version="1.0" encoding="ISO-8859-1"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:h="http://www.w3.org/TR/html4/" xmlns:j="http://www.w3.org/TR/scxml/"> <xs:element name="root"> <xs:complexType> <xs:sequence> <xs:element name="h:table"> <xs:complexType> <xs:sequence> <xs:element name="h:tr" type="xs:string"/> <xs:element name="h:t...

PHP/XML (or PHP/MySQL) CMS
I'm looking for a PHP/XML CMS (or a PHP/MySQL CMS) for managing a large corporate website with a lot of different information. I have found some CMS, but they are just not good enough. Can you recommend one ? thanks in advance. Nona Me wrote: > I'm looking for a PHP/XML CMS (or a PHP/MySQL CMS) for > managing a large corporate website with a lot of different information. > I have found some CMS, but they are just not good enough. > > Can you recommend one ? > > thanks in advance. > > try www.mamboserver.com/ imho top-notch reg. sh -- "The goal of Computer Science is to build something that will last at least until we've finished building it." -- unknown Stefan Hegenbart wrote: >> I have found some CMS, but they are just not good enough. >> >> Can you recommend one ? >> > > try www.mamboserver.com/ > imho top-notch Or if you need something really mighty: www.typo3.org Nona Me wrote: > I'm looking for a PHP/XML CMS (or a PHP/MySQL CMS) for > managing a large corporate website with a lot of different information. > I have found some CMS, but they are just not good enough. > > Can you recommend one ? > > thanks in advance. > > > From - Thu ezPublish: http://www.ez.no/ ...

How to write tcl generated xml file into a new file
Hi, I have generated a xml file using xmlgen. After running the tcl script the ouput is displayed on the terminal . I want to take the terminal output into a xml file. Any Suggestion ???/ Thanks Ranjan On Nov 25, 12:46=A0pm, gyana behera <ranjan....@gmail.com> wrote: > Hi, > > I have generated a xml file using xmlgen. > After running the tcl script the ouput is displayed on the terminal . > I want to take the terminal output into a xml file. > > Any Suggestion ???/ > > Thanks > Ranjan Either redirect the output of the script to the xml-file. (xmlgen > output.xml) or open the file in the script: set f [open $filename w] then use puts $f instead of puts to output to the file and finally close the file: close $f Note that all this is covered in the Tcl tutorial, which is definitely worth a visit. (http://www.tcl.tk/man/tcl8.5/tutorial/ tcltutorial.html) Mark ...

Problem converting XML with XSLT to another XML
Hallo, I have a problem converting a XML file to a other. I have no idea how I can do this. I try it for a long time but I can not find a solution. Has anyone a Idea? Below you can find my Input XML Document, Output XML Document and my scratch XSLT file. At the end is my request Output XML. Greetings H. Kaya My last scratch xslt: <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml"/> <xsl:key name="kDistinctCarDealer" match="CARDEALER" use="."/> <xsl:key name="kDistinctCity" match="CITY" use="."/> <xsl:template match="/"> <xsl:for-each select="ROWSET/ROW/CITY[generate-id() = generate-id(key('kDistinctCity',.))]"> <xsl:apply-templates select = ".." /> </xsl:for-each> </xsl:template> <xsl:template match="CARDEALER"> <xsl:text disable-output-escaping="yes"> &lt;CARDEALERS&gt;</xsl:text> <xsl:for-each select="/ROWSET/ROW/CARDEALER[generate-id() = generate-id(key('kDistinctCarDealer',.))]"> <xsl:copy-of select="."/> </xsl:for-each> <xsl:text disable-output-escaping="yes"> &lt;/CARDEALERS&gt;</xsl:text> </xsl:template> </xsl:stylesheet> It Pr...

read an XML file in TCL
Hello I am looking to read an XML file into my TCL program and extract information. How do we read an XML file in TCL? Are there man pages that describe these? Thanks krithiga one way is: http://wiki.tcl.tk/tdom another (and faster, but should be used only for valid stuff) is http://wiki.tcl.tk/11020 Torsten Edler wrote: > another (and faster, but should be used only for valid stuff) is > I'm curious as to this assertion that the shallow regexp parser is faster than tdom, I would have expected things to be the other way around. Do you have a benchmark? Were you testing tdom building a DOM tree or just SAX parsing (the latter would be a fairer comparison)? My own brief benchmark (parsing the XML 1.0 spec, ~200KB) produced these results: proc ParseXMLRegexp xml { XML::Init $xml while 1 { lassign [XML::NextToken] type val attr etype if {$type eq "EOF"} { break } } } proc ParseXMLTdom xml { dom parse $xml doc } puts "Regexp: [time { ParseXMLRegexp $xml } 10]" puts "Tdom: [time { ParseXMLTdom $xml } 10]" output: Regexp: 2419835.7 microseconds per iteration Tdom: 52872.1 microseconds per iteration which makes tdom roughly 45X faster than the regular expression parser, and that's with tdom building and destroying a full DOM tree. -- Neil Hi Neil, i typed my answer a bit too fast and mixed up TclXML with TcLDOM. Few months ago i had to read and extract all data from an XML-...

PHP XML access problem
Okay, I'm trying to make an AJAX-type application that uses an XMLHttpRequest to a PHP page which processes an XML document, getting elements, and printing them out. When I run it through, the only errors that I get are 2 PHP errors from the PHP page that accesses the XML document (since there is another PHP page I use that auto- generates the AJAX application). They are the following (verbatim): Warning: DOMDocument::loadXML() [function.DOMDocument-loadXML]: Empty string supplied as input in /usr/local/lsws/DEFAULT/html/html/ memberaccess.php5 on line 11 Fatal error: Call to undefined...

Tcl/XML parser problem
Hi. Can anybody help me resolve the problem.=20 This is my code: [code] package require tdom 0.7.5 set xml {<teryt> <catalog date=3D"2013-01-01" type=3D"all" name=3D"TERC"> <row> <col name=3D"WOJ">02</col> <col name=3D"POW"/> <col name=3D"GMI"/> <col name=3D"RODZ"/> <col name=3D"NAZWA">DOLNO=C5=9AL=C4=84SKIE</col> <col name=3D"NAZDOD">wojew=C3=B3dztwo</col> <col name=3D"STAN_NA">2013-01-01</col> <col name=3D"OPIS"> <linia>=20 </linia><linia>Kaucja: 2 000,00 z=C5=82 </linia><linia>Informacje zawarte w opisie maj=C4=85 charakter ori= entacyjny i nie stanowi=C4=85 oferty handlowej. </linia><linia> </linia><linia>Oferta wys=C5=82ana z programu IMO dla biur nieruch= omo=C5=9Bci </linia><linia/> </col> </row> <row> <col name=3D"WOJ">02</col> <col name=3D"POW">01</col> <col name=3D"GMI">01</col> <col name=3D"RODZ">1</col> <col name=3D"NAZWA">Boles=C5=82awiec</col> <col name=3D"NAZD...

Parse XML files with PHP
Hullo everybody, gals and guys! I have been looking for ages for some API to parse a very large XML file, with thousands of nodes in it. I needed to parse the XML file and access its nodes and children. In particular I needed to get certain children from a specified path in the passed XML file. Unfortunately all the classes I found didn't help that much (in particular the CXml you find named in Google).. I got an arry as a result, and it was too difficult to work with it.. But.. luckily I found what I was looking for! It's called MiniXML, you can download at http://minixml.psychogeni...

How to convert csv file to XML using XML::Simple?
I need to take a comma separated value (csv) file and convert it to XML. I'm trying to do this with XML::Writer. Using XML::Writer I can see how to convert FROM an XML document, but I don't see how to take a csv file and convert it to XML. If I had a csv file like this: Robert, Smith, 123 Main St. Jane, Smith, 456 Market St. William, Watson, 789 First Ave. How would I convert that to an XML file like this: <?xml version="1.0" ?> <ADDRESSBOOK> <CONTACT> <FIRST_NAME> Robert </FIRST_NAME> <LAST_NAME> Smith </LAST_NAME> ...

Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser)
Hello Usenet. I'm subject to some confusion with XML and UTF8. I'm working with XML-Simple and I try to decode some XML with with german umlauts (ISO-8859-1). The first XML line declared the encoding correct (see code below). But I'm getting different results using XML-Simple with the default XML parser named XML::Sax and a second parser named XML::Parser. The following code tries to decode the mini XML file and prints the UTF8 flags of the resulting strings. Can someone run this code on his machine and post the results? Thanks. The results on my machine are this: ���ä...

PHP XML-XML curl function not working. Please help
Hi Everyone, I'm trying to get the following php script to work with an ebay API. It sends XML and then returns XML and formats it into links. THing is it doesn;t work, and I'm not sure why. Can anyone see where I'm going wrong? Thank you in advance, Raj <?php $query = 'ipod'; $endpoint = 'http://open.api.ebay.com/shopping?'; $resp = simplexml_load_string(constructPostCallAndGetResponse($endpoint, $query)); if ($resp) { $results = ''; foreach($resp->Item as $item) { $link = $item->ViewItemURLForNaturalSearch; $tit...

UPnP xml file to WSDL xml file
Hello, could somebody help me to convert the below UPnP service file to WSDL web service file: <serviceList> <service> <serviceType> urn:schemas-upnp-org:service:PowerSwitch:1 </serviceType> <serviceId> urn:upnp-org:service:PowerSwitch:1 </serviceId> <controlURL>/upnp/control/power1</controlURL> <eventSubURL>/upnp/control/power1</eventSubURL> <SCPDURL>/blenderpowerSCPD.xml</SCPDURL> </service> thanks in advance bobby I tried to combine UPnP servive and blenderpowerSCPD.xml and come up with WSDL web service file as below: UPnP services: <serviceList> <service> <serviceType> urn:schemas-upnp-org:service:PowerSwitch:1 </serviceType> <serviceId> urn:upnp-org:service:PowerSwitch:1 </serviceId> <controlURL>/upnp/control/power1</controlURL> <eventSubURL>/upnp/control/power1</eventSubURL> <SCPDURL>/blenderpowerSCPD.xml</SCPDURL> </service> .... SCPD file <actionList> <action> <name>SetSpeed</name> <argumentList> <argument> <name>Speed</name> </argument> </argumentList> </action> ... </actionList> NOW the WSDL is as follows: <?xml version="1.0" encoding="UTF-8"?> <definitions name="Device Control" targetNamespace="http://shemas.UPnP.org/"> <messa...

Adressing node element when parsing xml with PHP and simple XML
I need to get the elements under this XML top structure using simplexml: <PKT> - <Result Name="GetTopWinnersForLastXMinutes" Success="1"> - <Returnset> - <Winner> I am trying to get the elements, associate them in one variable and foreach them under <Winner> like this: foreach($xml->Result.Returnset.Winner as $Winner) But the resulting page is blank. Could anyone please give me a hint? On 28 Nov 2009, Nosferatum <john.olav.o@gmail.com> wrote: > I need to get the elements under this XML top structure using > simplexml: > <PKT> > - <Result Name="GetTopWinnersForLastXMinutes" Success="1"> > - <Returnset> > - <Winner> > > I am trying to get the elements, associate them in one variable > and foreach them under <Winner> like this: > foreach($xml->Result.Returnset.Winner as $Winner) foreach ($xml->Result->Returnset->Winner as $Winner) { /* ... */ } > But the resulting page is blank. Could anyone please give me a > hint? In addition to the above, you can use XPath: <?php /* instantiate a SimpleXMLElement object ... */ $result = $xml->xpath('Result/Returnset/Winner'); foreach ($result as $node) { /* ... */ } ?> -- Curtis Dyer <? $x='<? $x=%c%s%c;printf($x,39,$x,39);?>';printf($x,39,$x,39);?&...

XML PHP
I am fairly familiar with PHP and MYSQL and I know a little about XML. I would like to know if it is possible to do queries on XML similar to the way that you do queries on MYSQL and then use the results. An example of a simple PHP/MYSQL setup. <?php $user="username"; $host="sqlserver"; $password="password"; $database="database"; $connection = mysql_connect($host,$user,$password) or die ("Couldn't connect to the server"); $db = mysql_select_db($database,$connection) or die ("Couldn't connect to the server"); $query = "SELECT * FROM database WHERE(Criteria)"; $result = mysql_query($query) or die ("Couldn't execute query."); while ($row = mysql_fetch_array($result)) { extract($row); echo"Set of instructions to carry out for each row in the result"; } ?> The question is, is it possible to do similar things with PHP/XML? Lets say that I have an XML file located at a certain URL and I want to run a query on it and use the results. 1. Is it possible? 2. What is the easiest way to do it? 3. How would I translate the above code to work with XML? 4. Is ther resource on the web on how to structure the queries? Any help is much appreciated. Rgds Joe On Thu, 13 Nov 2003 15:08...

XML to XML
I have a gnucash file that I'm trying to transform into an identical XML file without the invoices. I've been at this for a while now. The gnucash file is in XML and the element I'm looking into is: <gnc:transaction> I want to ignore those that contain <slot:key>gncInvoice</slot:key> which is a child of slot which is a child of slots which is a child of transactions. Any help you're willing to provide would be greatly appreciated. Thanks. Classic application for XSLT. Start with the identity transformation, then add a template which matches the ones you want to treat specially and yields no output. From your description that would be match="gnc:transaction[transactions/slots/slot/slot:key='gncInvoice']" with the namespaces declared appropriately in the stylesheet. (That looks like a somewhat unlikely markup design to me, but since I haven't played with gnucash at all I'm taking your word for it.) -- () ASCII Ribbon Campaign | Joe Kesselman /\ Stamp out HTML e-mail! | System architexture and kinetic poetry Actually, from the Relax-NG schema for gnucash, it looks like it should be more like "gnc:transaction[trn:slots/slot/slot:key='gncInvoice']" with gnc:, trn:, and slot: all bound to the appropriate namespace URIs. The fact that some of their elements -- eg <slot> -- aren't in any namespace is probably left over from a pre-namespaces initial design, as is their now-brok...

PHP currency converter with XML feed
I'm having trouble to modify this code(currency converter, a combination of javascript and php, which uses an XML feed from http://www.ecb.int/ to get up to date exchange rates) to work with http://www.bank.lv/vk/xml.xml Not worked for me. Any help will be appreciated. <?php $real_currency_names = array(); $real_currency_names['EUR'] = "Euro"; $real_currency_names['USD'] = "US Dollar"; $real_currency_names['JPY'] = "Japanese Yen"; $real_currency_names['BGN'] = "Bulgarian Leva"; $real_curr...

Sourcing a TCL file from within a tcl file
I am a newbie which I am sure I don't need to state :) I am trying to create a variable with a TCL file that will source another tcl file when I type the variable name something like this if I enter A through my keyboard then source a.tcl Can someone show me how to do this thanks guy On Dec 10, 1:15=A0pm, guy <gcoletta2...@gmail.com> wrote: > I am a newbie which I am sure I don't need to state :) > > I am trying to create a variable with a TCL file that will source > another tcl file when I type the variable name > > something like this > > if I enter A through my keyboard =A0then source a.tcl > > Can someone show me how to do this > > thanks > guy What you are asking is not hard. Will your program have a graphical user interface? Aric On Dec 10, 3:26=A0pm, Aric Bills <aric.bi...@gmail.com> wrote: > On Dec 10, 1:15=A0pm, guy <gcoletta2...@gmail.com> wrote: > > > I am a newbie which I am sure I don't need to state :) > > > I am trying to create a variable with a TCL file that will source > > another tcl file when I type the variable name > > > something like this > > > if I enter A through my keyboard =A0then source a.tcl > > > Can someone show me how to do this > > > thanks > > guy > > What you are asking is not hard. =A0Will your program have a graphical > user interface? > > Aric no I am just using this script...

php and xml
newbie to this topic... I'm currently using php4.3.... which library is better to manipulate xml document in php language? how 'bout PEAR? tks laura ...

parsing an xml file via php
hey everybody, does anyone know a good internet page where I can found some examples how to parse xml files by php..... all the pages I found give me too little information, so I was not able to solve my whole prob. thanks in advance, thomas Hi, I used clsParseXML. This is the header from the file itself: /* XML Parser Class by Eric Rosebrock http://www.phpfreaks.com Class originated from: kris@h3x.com AT: http://www.devdump.com/phpxml.php Usage: <?php include 'clsParseXML.php'; $xmlparse = &new ParseXML; $xml = $xmlparse->GetXMLTree('/path/to/xmlfile.xml')...

XML or not XML?
I am developing a simple MySQL database editor, and am looking into creating an PHP/AJAX app as the GUI. A lot of this in new ground, and much more is dusting off things I haven't used in a while. My question though involves whether or nor to employ XML. I did some XML a few years back, but don't typically bother anymore. As I see it XML is great when I need to have an app with a standard data presentation that other developers can easily interface. I.E. like a bank statement that may feed a variety of applications developed by a variety of clients. However, if I am develo...

Php into XML
Heelo everybody. I am using XML and XSL to analyse a text. Now, I am trying to integrate php into the XML code, in order to make the XML page dynamic. Yet the parser doesn't even read the php code embedded in the xml page. Here is the beginning of my XML page, inf-dev.xml ----- ?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE inferno SYSTEM "file:/Users/davidebenini/Documents/Universita%CC%80/Dottorato/inferno/inferno.dtd"> <?xml-stylesheet type="text/xsl" href="inf-dev.xslt"?> <inferno> <filtro>FILTRO: <?php echo "Filtro passsato in php"; ?>-</filtro> <canto> <n>1</n> <passo> <vv>1</vv> <dante> <v>Nel mezzo del cammin di nostra vita</v> </dante> <carson> <v>Halfway through the story of my life</v> </carson> <nota> <n>Carson introduce story</n> </nota> </passo> <passo> <vv>14</vv> <dante> <v>l� dove terminava quella valle</v> </dante> <carson> <v>hill; here, thre valley formed a cul-de-sac</v> </carson> ...

php and xml
hi, this is a bit of an advice thing. iv just finished a degree in multimedia, where i learned the usuals... html flash director javascript i also learned php and i have been told that i should get to grips with xml as this combination is verry useful so iv been messing arround with xml for the past couple of days trying to figure out how the two would work together. i just cant grasp the idea.. on thought i have had is that you could use php with a database to generate xml but surely that would not be parsed as xml as it would have the .php extension.. as i say im strugling to get this ...

Web resources about - TCL/PHP/XML problem: I need to convert an XML file into a TCL list - comp.lang.php

Resources last updated: 3/16/2016 4:02:03 AM