473,795 Members | 3,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8149
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...@yaho o.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 XMLStreamWriter http://www.java2s.com/Tutorial/Java/0440__XML/UsingXMLStreamW ritertoc...

--

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...@yaho o.dewrote:
>Java 6 has XMLStreamWriter http://www.java2s.com/Tutorial/Java/0440__XML/UsingXMLStreamW ritertoc...

Thanks. Is there any thing available for this with Java 1.5, any open
source app?
<http://en.wikipedia.or g/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*******@yaho o.dewrites:
>Java 6 has XMLStreamWriter

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

Here, it seems to be the other way round:

xtw.writeStartE lement("http://www.w3.org/TR/REC-html40", "a");
xtw.writeAttrib ute("href", "http://www.java2s.com" );
xtw.writeCharac ters("here");
xtw.writeEndEle ment();

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

So, more correct names to me would be:

»writeEndTag()« ,
»writeEndOfElem ent()«, or
»writeElementEn ding()«.
You're not writing tags with this, you're writing /events/.

So writeStartEleme nt 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******@progre ss.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.apa che.xml.interna l.serialize.XML Serializer serializer =
new com.sun.org.apa che.xml.interna l.serialize.XML Serializer
( fileOutputStrea m, outputFormat);
serializer.star tDocument();
{ serializer.star tElement("", "example", "example",
new com.sun.org.apa che.xml.interna l.serializer.
AttributesImplS erializer() );
{ final char[] data = "test text" . toCharArray();
serializer.char acters( data, 0, data.length );
serializer.endE lement( "", "example", "example" ); }
serializer.endD ocument(); }}}
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.comwrite s:
>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
4262
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) and puts values in a number of arrays and then puts the contents of the array in a HTML table. I'd like to keep the array structure. I've checked out all sorts of different javascript parsers but have not met with a great deal of success with any...
4
3091
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 supported and has good documentation! If there's nothing suitable for Solaris a command line program for Windows might do - currently using XMetaL/XMLSpy parsers which aren't really suited to large files.
9
1517
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 in a good way. I've tried google many times looking for some good document article that talks about C I/O and parsing files, most of the docs that I came across just talk about basic I/O things I can also learn from reading my man pages. Any...
25
12763
by: Ali-R | last post by:
Hi, Is there a parser which parses CSV files? Thanks for your help. Reza
6
3889
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 of the web app 3)restarting IIS 4)recreating the virtual dir in IIS 5)playing with any and all settings I could find for the web app in IIS, including changing permissions 6)recopying the machineconfig file from my asp v1.4... onto my local server
5
3798
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 file. Because I set some properties in parser, which may cause to changes between actual and parsed. What I expect is the exact XML file structure is to be available into another XML file (incl white spc's) after SAX parsing. Below is a snippet...
28
3597
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 THOROUGHLY BEFORE RESPONDING; OR ASK QUESTIONS TO CLARIFY. I *WILL* APPRECIATE ANY CONSTRUCTIVE REPLY. Greetings! I am in the process of creating a template for a site. The site will be *true* XHTML 1.1. That is, it will validate as XHTML 1.1 on...
28
16424
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 write a safe but easy implementation (i.e. no codedom) for an IBindingListView.Filter (by compiling to a Predicate<T>). Anybody know if this is possible at all? Marc
4
2572
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
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10436
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.