Forum OpenACS Q&A: Re: Reading a XML file from a web url

Posted by Neophytos Demetriou on
Off the top of my head (haven't tested, should work though)

package require tdom
set filename "yourfile"
set fp [open $filename]
set xml [read $fp]
close $fp
set doc [dom parse $xml]
set node [$doc selectNodes {//formatted_address}]
set address [$node asText]
# alternative:
# set address [$doc selectNodes{string(//formatted_address)}]
$doc delete

Posted by naveen cheguri on
Hi Neophytos

I got this error if I use dom parser. When I google this error I found that tDom is not installed.

invalid command name "dom"
while executing
"dom parse $xml"

Is there any other way I can parse my xml file


Posted by Toni Vila on
Hi Naveen,

if you want to manage xml better use tDom.

Its pretty easy intall tDom package, from openAcs Doc:

step 4.e:

After download and untar tDom package source

Install tDOM

[root nssha1]# cd ../tDOM-0.8.0/unix

Edit the CONFIG file. Uncomment the instructions meant for AOLserver 4, but edit it to look like this:

../configure --enable-threads --disable-tdomalloc
--prefix=/usr/local/aolserver --with-tcl=/usr/local/lib

Note that the location of the Tcl library may vary on differnt platforms (e.g. for Debian 3.0: --with-tcl=/usr/lib/tcl8.4)

Now you can compile and configure tDOM

[root unix]# sh CONFIG
[root unix]# make install


Posted by Gustaf Neumann on

This error message shows, that you are not using OpenACS, where tdom is preloaded. To load tDOM in a decent configured tcl shell, use "package require tdom". If tcl does not find tdom, then either you tcl-path (variable "auto_path" in Tcl) is incorrect, or you have to install tdom. On systems like ubuntu/debian, you can use "apt-get install tdom". But of course, you can get the sources and compile yourself, but for a beginner i would recommend to focus on the task.