aspose file tools*
The moose likes Java in General and the fly likes SAX model for XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "SAX model for XML" Watch "SAX model for XML" New topic
Author

SAX model for XML

Henadeerage Henadeera
Greenhorn

Joined: Aug 13, 2011
Posts: 12
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

Joined: Jul 08, 2003
Posts: 24184
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Henadeerage Henadeera
Greenhorn

Joined: Aug 13, 2011
Posts: 12
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

Joined: Jul 08, 2003
Posts: 24184
    
  34

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

Joined: Aug 13, 2011
Posts: 12
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...
 
 
subject: SAX model for XML