Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Document Object Tree creation using SAX Parser

 
clyde melly
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want a Document object tree to be created using SAX parsers instead of DOM.What would be the approach to it.Any working example would be of great of immense help.Thanx in advance.
 
Hari Vignesh Padmanaban
Ranch Hand
Posts: 578
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This post will be answered more prompty and correctly in the
..XML and Related Technologies

post your question there ..good luck!
 
Paul Clapham
Sheriff
Posts: 21572
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The approach would be to build the DOM yourself. When the startElement method is called you would create an Element node and add it as the last child of the current Element (or make it the root if there is nothing yet), then change that node to be the current Element. When the endElement method is called you would change the current Element back to the parent of the current Element. And when the characters() method is called you would make a Text node and add it as the last child of the current Element. I have left out attribute processing and other things like comments, and you should watch out for namespaces.

I am not going to produce anything more "working" than that because I don't see the point. If you could produce a DOM directly via a DocumentBuilder then why on earth would you write all that code to do it via SAX? One of the main reasons for using SAX is that you don't have to build the entire DOM in memory; if you do need the DOM then use a DocumentBuilder to construct it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic