ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> Tclxml-users
Tclxml-users
Re: [Tclxml-users] help: beginner
by Steve Ball other posts by this author
Nov 19 2004 10:49PM messages near this date
[Tclxml-users] help: beginner | [Tclxml-users] 11'th Annual Tcl/Tk Conference Audio Casting
Cedric,

The first thing you must realise is that your XML document has two 
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 
discovered "-elementstartcommand" that tells you when an element 
starts.  This callback gives you the name of the element ("Hello").

The other call back that you need is "-characterdatacommand".  This 
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 
"-elementendcommand".  This callback tells you when an element 
finishes, so you can tell which data belongs to what element.

You may wish to review some of the example scripts included with the 
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 
>  files
>  and extract values of tags, I have an XML file like this:
> 
>  test.xml:
> 
>  <?xml version='1.0'?>
>   <Hello>145590</Hello>
> 
>  What I have to do if I want to parse this document and the tag Hello 
>  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=$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édric,
> 
>  Dr, Phd,
>  Marie Curie Fellow, post doctorate
>  VICTOR project
>  Agfa Gevaert, RDM/Physics & Analytics
>  + 32 (0) 3 444 3077,
>  cedric.marchessoux@[...].com
>  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
>  Tclxml-users@[...].net
>  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
Steve.Ball@[...].com  +---------------------------+---------------------
Ph. +61 2 6242 4099   |   Mobile (0413) 594 462   | Fax +61 2 6242 4099



-------------------------------------------------------
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
Tclxml-users@[...].net
https://lists.sourceforge.net/lists/listinfo/tclxml-users
Thread:
Cedric Marchessoux
Steve Ball

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved