473,378 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

SAX Parser for creating (not parsing) XML document

Hi

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
Jul 21 '08 #1
6 8119
Naresh Agarwal wrote:
Hi

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?
Java 6 has XMLStreamWriter
http://www.java2s.com/Tutorial/Java/...ateXMLfile.htm
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 21 '08 #2
On Jul 21, 4:09 pm, Martin Honnen <mahotr...@yahoo.dewrote:
Naresh Agarwal wrote:
Hi
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?

Java 6 has XMLStreamWriterhttp://www.java2s.com/Tutorial/Java/0440__XML/UsingXMLStreamWritertoc...

--

Martin Honnen
http://JavaScript.FAQTs.com/
Thanks. Is there any thing available for this with Java 1.5, any open
source app?

Best
Naresh
Jul 22 '08 #3
Mon, 21 Jul 2008 21:46:42 -0700 (PDT), /Naresh Agarwal/:
On Jul 21, 4:09 pm, Martin Honnen <mahotr...@yahoo.dewrote:
>Java 6 has XMLStreamWriterhttp://www.java2s.com/Tutorial/Java/0440__XML/UsingXMLStreamWritertoc...

Thanks. Is there any thing available for this with Java 1.5, any open
source app?
<http://en.wikipedia.org/wiki/StAXlists three implementations:
* http://stax.codehaus.org/ Reference Implementation
* Woodstox Open source StAX implementation
* https://sjsxp.dev.java.net is Sun's Stax implementation
--
Stanimir
Jul 22 '08 #4
Stefan Ram wrote:
Martin Honnen <ma*******@yahoo.dewrites:
>Java 6 has XMLStreamWriter

Often, people use »tag« for »element«.

Here, it seems to be the other way round:

xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "a");
xtw.writeAttribute("href", "http://www.java2s.com");
xtw.writeCharacters("here");
xtw.writeEndElement();

. It seems as »writeEndElement« is supposed
to write the end /tag/, i.e., "</a>".

So, more correct names to me would be:

»writeEndTag()«,
»writeEndOfElement()«, or
»writeElementEnding()«.
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 <al******@progress.com
XQuery, XSLT, XML Schema and EDI Toolset <http://www.stylusstudio.com/
<There is no problem that brute force and ignorance cannot overcome <>
Jul 22 '08 #5
22 Jul 2008 16:31:54 GMT, /Stefan Ram/:
Another way to write XML with pre-1.6-Java:

com.sun.org.apache.xml.internal.serialize.XMLSeria lizer serializer =
new com.sun.org.apache.xml.internal.serialize.XMLSeria lizer
( 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_...etscape.net%3e

--
Stanimir
Jul 23 '08 #6
Stefan Ram a écrit :
Naresh Agarwal <na************@gmail.comwrites:
>Is there any thing available for this with Java 1.5, any open
source app?

Writing XML is simpler than reading XML.

So, sometimes, one can get by with no library at all:

outStream.print( "<" );
outStream.print( type );
outStream.print( ">" );
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.h...ateFromScratch
of course, you can loop on whatever you want to create content (merge
thousand XML files for example:
http://reflex.gforge.inria.fr/tips.h...rsingFragments )

then pipe the created doc to an XSLT serializer :
http://reflex.gforge.inria.fr/tips.h...tSerialization

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 !
Jul 24 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: annoyingmouse2002 | last post by:
Hi there, sorry if this a long post but I'm really just starting out. I've been using MSXML to parse an OWL but would like to use a different solution. Basically it reads the OWL (Based on XML)...
4
by: billcoumbe | last post by:
any recommendations? I'm looking for something that will just run from the unix command line to validate large (20-50Mb) XML files against an XML DTD. Ideally something that is actively...
9
by: Jonas Geiregat | last post by:
I'm trying to parse a configuration file, this is the first time I'm trying something like this, and it seems hard. C's I/O functions are a mess and hard to use , that is if you want to write code...
25
by: Ali-R | last post by:
Hi, Is there a parser which parses CSV files? Thanks for your help. Reza
6
by: ST | last post by:
Hi, I keep getting the parser error, and I have no idea why. I've tried a number of things including: 1)building/rebuilding about 100x 2)making sure all dll's are in the bin folder in the root...
5
by: baskarpr | last post by:
Hi all, I my program after parsing in SAX parser, I want to write the parse result as an XML file. I want to ensure that there should be no difference between source XML file and parse result xml...
28
by: Neo Geshel | last post by:
NOTE: PAST EXPERIENCE HAS SHOWN ME THAT MANY ON USENET FAIL TO READ ARTICLES PROPERLY PRIOR TO ANSWERING. I AM LOOKING FOR VERY SPECIFIC INFORMATION, THEREFORE PLEASE READ AND UNDERSTAND...
28
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to...
4
by: fbrewster | last post by:
I'm writing an HTML parser and would like to use Internet Explorers DOM parser. Can I use Internet Explorers DOM parser through a web service? thanks for the help
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.