• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Document Object Tree creation using SAX Parser

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 578
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 27235
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic