Re: Parsing question from a newbie.

Robert Bielik <[email protected]> Wed, 30 Mar 2011 06:45:15 +0200
Newsgroups gmane.text.xml.expat.general
Message-ID <[email protected]>
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