|
From: Steve B. <Ste...@zv...> - 2004-11-19 22:49:20
|
Cedric,
The first thing you must realise is that your XML document has two=20
components:
1. An element, named "Hello", and
2. character data, with the value "145590".
You use different callbacks to get those parts. You've already=20
discovered "-elementstartcommand" that tells you when an element=20
starts. This callback gives you the name of the element ("Hello").
The other call back that you need is "-characterdatacommand". This=20
callback gives you the value of the character data ("145590").
This modification to your script will give you both data items:
proc tutu {data} {
global f
$f.valueb configure -text $data
}
set parser [::xml::parser -elementstartcommand toto \
-characterdatacommand tutu]
$parser parse [read $filein]
Another callback you may wish to know about is the=20
"-elementendcommand". This callback tells you when an element=20
finishes, so you can tell which data belongs to what element.
You may wish to review some of the example scripts included with the=20
TclXML distribution for more detail on how these callbacks work.
In review, remember that with XML:
A) Elements have a name, but they have no value,
B) Character data (text) has a value, but no name,
C) Attributes have a name and a value.
This also applies to the DOM and therefore TclDOM.
HTHs,
Steve Ball
On 20/11/2004, at 4:08 AM, Cedric Marchessoux wrote:
> I am a user of tcl/tk and vtk. I want to use tclxml in to parse xml=20
> files
> and extract values of tags, I have an XML file like this:
>
> test.xml:
>
> <?xml version=3D'1.0'?>
> <Hello>145590</Hello>
>
> What I have to do if I want to parse this document and the tag Hello=20=
> is in
> th xml, I want to get the value ?
>
> proc toto {Hello tata} {
> global amax f
> set amax $tata
> $f.labela configure -text "a=3D$amax"
> $f.valuea configure -textvariable $amax
>
> }
>
> set filein [open "./test.xml" r]
>
> set parser [::xml::parser -elementstartcommand toto]
>
> $parser parse [read $filein]
>
> Thank you in advance,
>
> C=E9dric,
>
> Dr, Phd,
> Marie Curie Fellow, post doctorate
> VICTOR project
> Agfa Gevaert, RDM/Physics & Analytics
> + 32 (0) 3 444 3077,
> ced...@ag...
> http://www.marchessoux.com
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: InterSystems CACHE
> FREE OODBMS DOWNLOAD - A multidimensional database that combines
> robust object and relational technologies, making it a perfect match
> for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8
> _______________________________________________
> Tclxml-users mailing list
> Tcl...@li...
> https://lists.sourceforge.net/lists/listinfo/tclxml-users
>
>
---
Steve Ball | XSLT Standard Library | Training & Seminars
Zveno Pty Ltd | Web Tcl Complete | XML XSL Schemas
http://www.zveno.com/ | TclXML TclDOM | Tcl, Web Development
Ste...@zv... +---------------------------+---------------------
Ph. +61 2 6242 4099 | Mobile (0413) 594 462 | Fax +61 2 6242 4099
|