File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SAX model for XML

 
Henadeerage Henadeera
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anybody know
how to insert an XML record to an XML file using SAX model.
I already know how to do it via DOM model. But it is memory intensive.

cheers,
Chinthaka
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SAX isn't a model; it's a series of events sent while parsing a document, without building up any kind of model. That's why it uses less memory, because there's no model! You therefore can't create a document using SAX -- it doesn't even make sense.
 
Henadeerage Henadeera
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest Friedman-Hill wrote:SAX isn't a model; it's a series of events sent while parsing a document, without building up any kind of model. That's why it uses less memory, because there's no model! You therefore can't create a document using SAX -- it doesn't even make sense.


Do you mean that ,using SAX ,can't be updated (insert xml record) an existing XML file ???
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henadeerage Henadeera wrote:
Do you mean that ,using SAX ,can't be updated (insert xml record) an existing XML file ???


That is exactly what I mean. Out of the box, SAX does nothing to help you write XML documents, only read them.

Now, to be fair, you could write a SAX event handler which re-sent the events it received, inserting new events as needed to represent your new or changed content; and then another one which, based on the events it received, wrote out an XML document. Then you could connect the first one to a SAX parser, and the second one to the first one, and you'd end up with a modified XML file. I've seen where people have done things like this, actually. But it's pretty crazy stuff.
 
Henadeerage Henadeera
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest Friedman-Hill wrote:
Henadeerage Henadeera wrote:
Do you mean that ,using SAX ,can't be updated (insert xml record) an existing XML file ???


That is exactly what I mean. Out of the box, SAX does nothing to help you write XML documents, only read them.

Now, to be fair, you could write a SAX event handler which re-sent the events it received, inserting new events as needed to represent your new or changed content; and then another one which, based on the events it received, wrote out an XML document. Then you could connect the first one to a SAX parser, and the second one to the first one, and you'd end up with a modified XML file. I've seen where people have done things like this, actually. But it's pretty crazy stuff.


Thanks for your explanation. This is really helped me...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic