• 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

Good tutorial for StAXParsing using Java

 
Greenhorn
Posts: 2
MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've got good Java skills but have been asked by client to use a XML file rather than a MySQL Database. Seems simple enough, read the data into a class, process data as required.

Been looking for a good tutorial I can use to follow along using StAX. Any ideas?

Been looking around and found some that are long on detail but don't really use a very complicated XML file (only a few tags, rather than one with many child elements with my XML files uses) or don't really explain in detail the method/classes required to walk the file.

Any suggestions?
 
Ranch Hand
Posts: 270
15
Android Angular Framework Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, M Parish:

I think "StAX" (if I am not misinformed) translates to "XML Pull Parsing".  I have used this on a small Android project, to pull data from a server.  I don't necessarily recommend using that for Android, because XML is not the tightest format.  But, I had all the other tools in place, and I have not settled this one for production, so it was quick to implement.  I see this as analogous to sorting a bunch of 'stuff' into the right containers. You have to ask for what you want next.

This is a resource for pull parsing:
http://www.xmlpull.org/

I have worked with several other XML technologies through the years.  Others to consider would be:
* SAX - this is a kind of "push" approach, where your code receives "event"-like callbacks for begin/end of tag, etc.  This one can take more programming effort, but is faster than some others.  Probably not any faster than pull, and you'd have to do more 'bookkeeping' with SAX--you have to track what tag is the parent of the current one (maybe even grandparent) if that is relevant.  I think of SAX as working at a supermarket bagging groceries as they come by.  You have to make sure they go into the right bag.
* DOM - fat city.  I avoid this, even though it looks easy at first glance.  It takes a multiple in memory of the document size.  There is also a JDOM which is better on space.  This approach requires a lot of checking of types as you walk the tree.
* JAX - Java XML.  This is one of my favorites: you autogenerate code based on the Schema for the documents, and then walk that.  It is like DOM but not as wasteful, and you get meaningful values at each level of he tree.  This will take more in-memory space than SAX.  But if you need all that information memory at once, and you do not have to marshal into some other data model, JAX can actually make you a usable model.  JAX underlies Oracle's APIs for SOAP.

I hope this helps.
 
M Parish
Greenhorn
Posts: 2
MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.

The application I'm working on will only run on an in-house website with no immediate plans for mobile access.  That being said, you never know.

Java XML look promising, and I'll look into it.

This may all not naught, seems a new management team is looking into migration of the existing data file to an ORACLE DB.  Guess I better brush up on my SQL skill set.  Did not a lot of this type of development about 10 years ago.
 
Saloon Keeper
Posts: 7585
176
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's an informative site, but be aware that StAX is now part of the standard Java API, so the API has changed somewhat. https://docs.oracle.com/javase/tutorial/jaxp/stax/index.html is a good starting point for that.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic