Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

How do you deal with this xml using Sax?

 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Thanks Bill! I've already deciphered that...I thought SAX was really that complicated...
 
reply
    Bookmark Topic Watch Topic
  • New Topic