From: Roedy Green on
I wrote a bit of code using SAX to extract data from an XML
configuration file whose structure I composed myself. I thought to
myself, "This can't be right". Nobody in their right mind would invent
something so clumsy to extract the data." I used as a model various
bits of code I found on the net. I am hoping this information was
obsolete.

Is there a more streamlined way to do this?

In this case the XML file is quite small, so perhaps a DOM approach
might be more appropriate.

Here is the XML file I want to extract data from:

https://wush.net/websvn/mindprod/filedetails.php?repname=mindprod&path=%2Fcom%2Fmindprod%2Fhtmlreflow%2Fhtmlreflow.xml

Here is the XSD schema for the file

https://wush.net/websvn/mindprod/filedetails.php?repname=mindprod&path=%2Fcom%2Fmindprod%2Fhtmlreflow%2Fhtmlreflow.xsd

Here is my parsing code
https://wush.net/websvn/mindprod/filedetails.php?repname=mindprod&path=%2Fcom%2Fmindprod%2Fhtmlreflow%2FConfigure.java

What bothers me is I explained in the XSD considerable detail about
the structure of the document, but none of this knowledge is
automatically used in extracting data.
--
Roedy Green Canadian Mind Products
http://mindprod.com

Every compilable program in a sense works. The problem is with your unrealistic expections on what it will do.
From: Mike Schilling on
Roedy Green wrote:
> I wrote a bit of code using SAX to extract data from an XML
> configuration file whose structure I composed myself. I thought to
> myself, "This can't be right". Nobody in their right mind would invent
> something so clumsy to extract the data." I used as a model various
> bits of code I found on the net. I am hoping this information was
> obsolete.
>
> Is there a more streamlined way to do this?
>
> In this case the XML file is quite small, so perhaps a DOM approach
> might be more appropriate.
>
> Here is the XML file I want to extract data from:
>
> https://wush.net/websvn/mindprod/filedetails.php?repname=mindprod&path=%2Fcom%2Fmindprod%2Fhtmlreflow%2Fhtmlreflow.xml
>
> Here is the XSD schema for the file
>
> https://wush.net/websvn/mindprod/filedetails.php?repname=mindprod&path=%2Fcom%2Fmindprod%2Fhtmlreflow%2Fhtmlreflow.xsd
>
> Here is my parsing code
> https://wush.net/websvn/mindprod/filedetails.php?repname=mindprod&path=%2Fcom%2Fmindprod%2Fhtmlreflow%2FConfigure.java

Os this the code you meant to post? There's no SAX in it.

>
> What bothers me is I explained in the XSD considerable detail about
> the structure of the document, but none of this knowledge is
> automatically used in extracting data.

To use sceham information to parse, use JAXB to generate Java classes that
correspond to your schema types, which will also have the logic to
deserialize themselves from XML.


From: Lew on
Roedy Green wrote:
> I wrote a bit of code using SAX to extract data from an XML
> configuration file whose structure I composed myself. I thought to
> myself, "This can't be right". Nobody in their right mind would invent
> something so clumsy to extract the data." I used as a model various
> bits of code I found on the net. I am hoping this information was
> obsolete.
....
> Here is my parsing code
> https://wush.net/websvn/mindprod/filedetails.php?repname=mindprod&path=%2Fcom%2Fmindprod%2Fhtmlreflow%2FConfigure.java

That's DOM code, not SAX code.

SAX code has a set of callbacks that you implement, none of which are present
in that class.

<http://www.saxproject.org/quickstart.html>
shows what you should be doing.

--
Lew
From: Roedy Green on
On Tue, 9 Feb 2010 08:12:28 -0800, "Mike Schilling"
<mscottschilling(a)hotmail.com> wrote, quoted or indirectly quoted
someone who said :

>
>Os this the code you meant to post? There's no SAX in it.

right. There is
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

Which lead me to believe I was using SAX, but actually it is a DOM
parse.

I would rephrase my question. It the code obsolete? Is there a better
way to do this that takes advantage of field type information in the
XSD schema? Is there a terser way to extract data?


--
Roedy Green Canadian Mind Products
http://mindprod.com

Every compilable program in a sense works. The problem is with your unrealistic expections on what it will do.
From: Mike Schilling on
Roedy Green wrote:
> On Tue, 9 Feb 2010 08:12:28 -0800, "Mike Schilling"
> <mscottschilling(a)hotmail.com> wrote, quoted or indirectly quoted
> someone who said :
>
>>
>> Os this the code you meant to post? There's no SAX in it.
>
> right. There is
> import org.xml.sax.SAXException;
> import org.xml.sax.SAXParseException;
>
> Which lead me to believe I was using SAX, but actually it is a DOM
> parse.
>
> I would rephrase my question. It the code obsolete? Is there a better
> way to do this that takes advantage of field type information in the
> XSD schema? Is there a terser way to extract data?

As I said, use JAXB to generate a class from the schema. Many web service
toolkits can do this too (e.g. Axis), but as far as I know, they need a WSDL
to start from.