• 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

How do you deal with this xml using Sax?

 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<PurchOrder>
<PurchOrderNo>1</PurchOrderNo>
<LastChanged>1/1/01</LastChanged>
....
<PurchOrderLine>
<PurchOrdLineNo>1</PurchOrdLineNo>
<LastChanged>1/1/01</LastChanged>
....
</PurchOrderLine>
....
</PurchOrder>

I have a repeatable element(<LastChanged> How do you parse this using SAX? Where do i put the code?startElement()?characters()?endElement()? I have a very huge XML File, so SAX is the way to go. Any kind soul out there willing to help?
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depends on what you really want to do with that element and its data.
You can put it in any of the methods you mentioned.

So, what exactly do you have to do with this element?

- m
 
Paulo Aquino
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to parse the xml then recreate it and put in inside a Stringbuffer, you might be wondering why would I parse a xml then just recrate it, actually I need to parse a huge xml and I would want to cut it section by section...so any leads?
 
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

Where do i put the code?startElement()?characters()?endElement()?


For SAX processing you have to write a class extending org.xml.sax.helpers.DefaultHandler. You attach an instance of this class to a parser and start the parser.
ANY output will have to be created by your various event handler methods - they can write to whatever you want. The parser just creates events, it is up to you to figure out how to handle them.

Bill
 
Paulo Aquino
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bill! I've already deciphered that...I thought SAX was really that complicated...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic