I have been using DOM parser to create XML documents. I want to use an
alternate mechanism to create XML document as size of my XML document
is large and I don;t want the overhead of DOM (where entire tree in
constructed in memory).
Like SAX APIs for parsing XML documents, Is there any thing like SAX
parser/APIs for creating XML documents?
Is there any other standard mechanism of creating XML document,
without requiring the entire tree structure to be constructed in
memory?
Thanks,
Naresh
Java 6 has XMLStreamWriter
http://www.java2s.com/Tutorial/Java/0440__XML/UsingXMLStreamWritertocreateXMLfile.htm
--
Martin Honnen
http://JavaScript.FAQTs.com/
Thanks. Is there any thing available for this with Java 1.5, any open
source app?
Best
Naresh
<http://en.wikipedia.org/wiki/StAX> lists three implementations:
> * http://stax.codehaus.org/ Reference Implementation
> * Woodstox Open source StAX implementation
> * https://sjsxp.dev.java.net is Sun's Stax implementation
--
Stanimir
You're not writing tags with this, you're writing /events/.
So writeStartElement means you are sending the StartElement
/event/ into the stream. writeEndElement means you are
sending the EndElement /event/ into the stream.
When using XMLStreamWriter, you must remember that you are
acting as the parser.
--
Tony Lavinio <> DataDirect <> Stylus Studio XML <> alav...@progress.com
XQuery, XSLT, XML Schema and EDI Toolset <> http://www.stylusstudio.com/
<> There is no problem that brute force and ignorance cannot overcome <>
> Another way to write XML with pre-1.6-Java:
>
> com.sun.org.apache.xml.internal.serialize.XMLSerializer serializer =
> new com.sun.org.apache.xml.internal.serialize.XMLSerializer
> ( fileOutputStream, outputFormat);
> serializer.startDocument();
> { serializer.startElement("", "example", "example",
> new com.sun.org.apache.xml.internal.serializer.
> AttributesImplSerializer() );
> { final char[] data = "test text" . toCharArray();
> serializer.characters( data, 0, data.length );
> serializer.endElement( "", "example", "example" ); }
> serializer.endDocument(); }}}
Here's more standard way of doing it without requiring
implementation specific classes (works with Java 1.4):
http://mail-archives.apache.org/mod_mbox/xml-xalan-j-users/200801.mbox/%3c4797292...@netscape.net%3e
--
Stanimir
hi,
IMHO, this is one of the worst practice
outStream.print( "<" );
outStream.print( type );
outStream.print( ">" );
outStream.print( "if (a<b ) {}" );
you'll have too many occasions to break your XML result ; rely on tools
made for that purpose that will produce well-formed XML
you can also use templates for creating SAX documents with RefleX :
http://reflex.gforge.inria.fr/tips.html#createFromScratch
of course, you can loop on whatever you want to create content (merge
thousand XML files for example:
http://reflex.gforge.inria.fr/tips.html#parsingFragments )
then pipe the created doc to an XSLT serializer :
http://reflex.gforge.inria.fr/tips.html#xsltSerialization
you can use it from the command line, embed it in a program, or deploy
it within a web server
tutorials are available here :
http://reflex.gforge.inria.fr/tutorial.html
I will talk about all that stuff at Balisage 2008 in Montreal, with a
focus on schema languages
http://www.balisage.net/Program.html#h245p
--
Cordialement,
///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !