1

I have never had to download an XML file in Java before and parse it after. I'm looking to download and parse this file http://api.irishrail.ie/realtime/realtime.asmx/getStationDataByNameXML?StationDesc=Bayside

All I want to do is read the train times. I've been reading about parsing XML but I'm not really getting anywhere with it. I just keep reading about parsers like stax, after that I'm a bit lost.

Can anyone give me some basic advice of what I need to do?

Peck3277
  • 1,383
  • 8
  • 22
  • 46
  • Check out this [link][1]..Should be something that you are looking for.. [1]: http://stackoverflow.com/questions/7373567/java-how-to-read-and-write-xml-files/7373596#7373596 – Works On Mine Feb 03 '14 at 15:30

4 Answers4

1

You can use JAXB for this and any other XML processing needs. Start here.

Sujith Surendranathan
  • 2,569
  • 17
  • 21
1

You can use DOM parser and new Java Architecture for XML Binding JAXB it will help you in marshalling (for converting an xml to Object) and unmarshalling(for converting an Object to xml)

link for the example

http://www.vogella.com/tutorials/JAXB/article.html

enter image description here

Girish
  • 1,717
  • 1
  • 18
  • 30
1

You can use the DOM Parser to create a Document object from the XML file.

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder(); 
Document doc = db.parse(new File(filename));

The DOM Parser creates a traversable tree from your XML data.

You can then pick out the data you need from the DOM tree using XPath.

gMok
  • 45
  • 8
0

try this library http://x-stream.github.io/download.html it is simple and fast to use to write and read xml from java.

facundofarias
  • 2,973
  • 28
  • 27
Matteo Gatto
  • 616
  • 11
  • 28