[Expat-discuss] How Can I get the value of an element using Expat apis?

Josh Martin Josh.Martin@abq.sc.philips.com
Tue, 17 Sep 2002 22:31:06 -0600 (MDT)


> Hi, I need pass the value of an element to a variable of a C program, By
> examples, the xml text: <a>hola<b>1</b></a>, How get the value of a and b
> elements for?.
> 
>  Marcela Godoy Pinilla.
> Ingeniero de Software
> mgodoy@adexus.cl
> 56-2-6861142
> ADEXUS.

Hello,

First, let me clear up a misconception you seem to have. Elements, such as the 
ones denoted by the <a> and <b> tags, do not have values, although they may 
contain attributes which have values (such as <a length="42">). The value of any 
attributes can be obtained with the handler that you specify with 
XML_SetStartElementHandler() (see the documentation). The text contained between 
a start and end tag such as the "hola" in <a>hola</a> is called character data, 
and does not technically have any relation to the tag, except as far as 
validation using the DTD is concerned. This character data can be obtained using 
the handler that you specify with XML_SetCharacterDataHander() (again, see the 
documentation). The only way to tell what tags the character data occured inside 
of is to keep track of which tags you are parsing inside of your 
StartElementHandler() function and your EndElementHandler() function.

 - Josh Martin