• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

tranverse back an xml using SAX Parsers

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

As we can traverse back and forth an xml using a DOM very easily, But since in SAX Parsers, the complete tree is not loaded in one go so normally we cannot traverse back.
Is there any way to do this?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No

Of course not, thats the whole point.

SAX parsers hand you one event at a time - it is up to the programmer to handle the information. Incidentally, you can not reliably just keep references to the event Attributes the parser hands you in a startElement(), in case you were thinking of back-tracking through stored events.

Bill
 
Marshal
Posts: 28193
95
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
I'm not sure why you would want to traverse back, but there's nothing stopping you from storing information which you might need later in the parsing process.
 
Pragya Patnaik
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey every parser uses SAX in back end.
DOM also uses SAX Parser. But it creats a document so we can traverse back(i think)..
similarly can we do any thing like this??
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ever since XML handling in Java started, very skilled people have labored on making the libraries more efficient.

Why do you think re-inventing the wheel (or the DOM) is a good idea?

Back off a couple of kilometers and try to state your problem in a general way without preconceived technology notions. You might be surprised at how easy the solution turns out to be.

Bill
 
Pragya Patnaik
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.. my actual problem was that... I have to use a SAX Parser. But i want a document, so need to convert the SAX result to a document...
I got a solution for that... by using SAXSource and DOMResult.
 
Paul Clapham
Marshal
Posts: 28193
95
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
Which is exactly what you would have, in a more straightforward way, if you just used a DOM parser. And don't forget that the DOM parser itself uses a SAX parser to traverse the input document.

Why exactly did you have to use a SAX parser? Whose idea was that?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic