-1

How can I parse xml from website using Java ?

For example this one http://rates.fxcm.com/RatesXML

Anyone knows how is it done?

Carlo Adap
  • 69
  • 1
  • 11

6 Answers6

2

Here's the Oracle Java/XML tutorial. That will give you an overview of the most common XML APIs for Java, together with their pros/cons.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
0

There are several XML libraries which you can use for this. jdom has always worked well for me.

Jon Kiparsky
  • 7,499
  • 2
  • 23
  • 38
0

You can use XML parser,there are so many resources on the web.

Additionally read those.

http://www.w3schools.com/xml/xml_parser.asp

http://www.perlmonks.org/?node_id=62782

Ruchira Gayan Ranaweera
  • 34,993
  • 17
  • 75
  • 115
0

I think simplest option is to use "xStream". All you need is to define a "Rates/Rate" POJO classes with appropriate member attributes and use something like below:

 Rates rates = (Rates) xstream.fromXML(xml);

Use two minute tutorial for further reference.

Yogendra Singh
  • 33,927
  • 6
  • 63
  • 73
0

My personal preference is dom4j. Powerful and easy to work with.

nwnoga
  • 577
  • 3
  • 12
  • 22
0

Your example is simple enough to parse manually using the DOM or SAX API, but I'd still suggest using an XML serialization API such as JAXB, XStream, or Simple instead because writing your own XML serialization/deserialization code is a drag.

Note that the XStream FAQ erroneously claims that you must use generated classes with JAXB:

How does XStream compare to JAXB (Java API for XML Binding)?

JAXB is a Java binding tool. It generates Java code from a schema and you are able to transform from those classes into XML matching the processed schema and back. Note, that you cannot use your own objects, you have to use what is generated.

It seems this was true was true at one time, but JAXB 2.0 no longer requires you to use Java classes generated from a schema.

If you go this route, be sure to check out the side-by-side comparisons of the serialization/marshalling APIs I've mentioned:

http://blog.bdoughan.com/2010/10/how-does-jaxb-compare-to-xstream.html http://blog.bdoughan.com/2010/10/how-does-jaxb-compare-to-simple.html

rob
  • 6,147
  • 2
  • 37
  • 56