Re: Parsing question from a newbie.

"Thomas, John" <[email protected]> Wed, 30 Mar 2011 11:38:53 -0700
Newsgroups gmane.text.xml.expat.general
Message-ID <[email protected]>
Rob,

Thanks for this info.  So, apparently:

1)  I must construct and maintain my own context (i.e. expat does not
provide global context).
2) The "right" place to DO that might be in the startElement() and
endElement() routines.
3) The "right" place to STORE this context would be in my userData
structure 
        (which I should expanded from the simple pointer to depth that
is used in the elements.c sample source code.)
4) In your explanation below when you showed:
        startElement: "size"
        valueData: "11.0"
        endElement: "size"
   I think you may have meant:
        startElement: "width"
        valueData: "11.0"
        endElement: "width"
   Would that be correct?

Thanks millions.

John
[email protected]


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf
Of Robert Bielik
Sent: Tuesday, March 29, 2011 9:45 PM
To: [email protected]
Subject: Re: [Expat-discuss] Parsing question from a newbie.

Thomas, John skrev 2011-03-30 03:37:
> Suppose that I have an XML snippet of the form:
>
> <myXML>
>    <size_1>
>      <height>8.5</height>
>      <width>11.0</width>
>    </size_1>
>    <size_2>
>      <height>8.0</height>
>      <width>10.0</width>
>    </size_2>
> </myXML>

First off, perfectly valid XML. There are no redundant elements.

> Second question: How (and when) do I obtain the context information 
> for a call to value_data_handler()?  Does it exist in a convenient 
> form and is there an expat-provided function call to get it?

You'll have to keep a tag on context by utilizing the call sequence from
Expat. It is after all SAX (simple api for XML) :)

You'll get called as follows:

startElement: "myXML"
startElement: "size_1"
startElement: "height"
valueData: "8.5"
endElement: "height"
startElement: "size"
valueData: "11.0"
endElement: "size"
endElement: "size_1"
startElement: "size_2"
startElement: "height"
valueData: "8.0"
endElement: "height"
startElement: "size"
valueData: "10.0"
endElement: "size"
endElement: "size_2"
endElement: "myXML"

Hope that helps.

Regards
/Rob
_______________________________________________
Expat-discuss mailing list
[email protected]
http://mail.libexpat.org/mailman/listinfo/expat-discuss