XML/XSD generation with SAX

Hello,

I'd like to generate xsd files from flat files.

I use an org.xml.sax.XMLReader implementation to do so.

My class sets up an org.xml.sax.ContentHandler on which I call

startElement(String namespaceURI,

String localName,

String qName,

Attributes atts)

when needed as well as

endElement(String namespaceURI,

String localName,

String qName)

My problem is that I only want to output elements which hold their values in attributes

like <xsd:enumeration value="YC4"/>.

My parser allways generates <xsd:enumeration value="YC4"></xsd:enumeration>

instead, but I need no end element tag.

The parser does not like ommiting the endElement() method call, at least I did not find out how to manage this. If I omit it, the vm runs out of memory.

Is there a way to handle the parsers behavior so that I get it like <xsd:enumeration value="YC4"/>?

Thanks

Matthias

[1005 byte] By [fd1380a] at [2007-11-26 19:17:32]
# 1
Your post is really confusing, so you should probably post the code that you're having problems with. SAX is used for parsing an existing XML file, but you say that you're parsing a flat file?
bckrispia at 2007-7-9 21:31:55 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Hello,

thanks for your feedback.

To your question:

Yes I use sax to generate XML from flat.

All you have to do ist to call the event mehtods of the handler object explcidly when needed.

I wont have access to the code as I am out of the office now for a couple of days, but I will do so on Monday.

Matthias

fd1380a at 2007-7-9 21:31:55 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Presumably you're talking about the serializer. Parsers read XML and produce internal representations of the data, serializers read internal representations and produce XML.

Anyway there's no difference in XML between the two forms of the empty element. Both are equally acceptable and they are equivalent. Compliant XML parsers do not care which form is used.

Is there a particular reason you care about this?

DrClapa at 2007-7-9 21:31:55 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

> Yes I use sax to generate XML from flat.

> All you have to do ist to call the event mehtods of

> the handler object explcidly when needed.

Interesting. I guess you [url=http://www.javazoom.net/services/newsletter/xmlgeneration.html]can use SAX[/url] plus a JAXP Transformer to generate XML. Ya learn something new every day. :)

To your original question; looking at the [url=http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/transform/OutputKeys.html]javax.xml.transform.OutputKeys[/url] API, I don't see any configuration parameter that will allow you to do this. Perhaps your underlying SAX parser supports this, but it doesn't appear to be part of the JAXP spec.

If your parser can't do this kind of output, you could always post-process the xml you generated with some regular expression to clean up empty elements.

So why is it necessary to have elements output in this format? The long format is still valid xml, albiet, less pretty.

bckrispia at 2007-7-9 21:31:55 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...