aspose file tools*
The moose likes XML and Related Technologies and the fly likes where to start with parsing XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "where to start with parsing XML" Watch "where to start with parsing XML" New topic
Author

where to start with parsing XML

J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 1003
    
  13

I'm finally able to consume web services through our proxy server and now I have a XML file. Where do I start with parsing? I'm confused by the plethora of parsers; SAX, DOM, XSLT, Xerces, etc., and don't know where to start.

If it makes a difference, I'm getting the XML from the National Weather Service to build a web page with the weather forecast. I don't want all our users constantly hitting the NWS website so I need to store this information. I'm thinking I need to populate a bean and store it in the context.

Any tips on how to get started? Am I on the right track?


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 1003
    
  13

So I stumbled onto this site. It seems like a decent approach, but I'm confused by this code:



What is that MyFile object in the last line? The page doesn't explain where this came from.

John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Jk Robbins wrote:I'm finally able to consume web services through our proxy server and now I have a XML file.

What is the XML file you are getting from the web services. Are you mentioning about the SOAP wsdl file?

SAX and DOM are popular XML programming interfaces. If it's like you need to parse an XML file and store it in a cache, you can use either of them and extract data from the desired nodes.

SAX and DOM examples will be plenty on the internet or if you search this forum.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

But that site is just a quick overview of what you would do if you knew how to use JAXB. A proper treatment of JAXB would require... well, however many pages the JAXB tutorial requires. It's a lot. I thought I had a copy on my machine but I don't, but anyway I recommend having a look at it. Your google keywords are jaxb tutorial (of course).
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 1003
    
  13

I should have been clearer. I'm using a REST call; no WSDL involved. This is what I have so far:



But now I'm not sure what to do with that Object created on line 34. I have a folder full of classes created by JAXB from the XSD file, including an ObjectFactory class, but don't know what the next step should be.

Any tips are welcome. Back to more tutorials...
 
wood burning stoves
 
subject: where to start with parsing XML