Question

I want to parse an XML file. The outcome has to be a list with the info about symbol="YHOO".

The XML file comes from yahoo using YQL. An example: http://goo.gl/xB84eN

private XMLStreamReader makeXML(URL url) throws XMLStreamException, IOException {
    InputStream stream = url.openStream();
    XMLInputFactory xmlif = XMLInputFactory.newInstance();
    XMLStreamReader xmlr =  xmlif.createXMLStreamReader(stream);

Now I want to get some data out of the XML using SAX. But I can't figure out how to get the attributes and elements using XMLStreamReader and his events described on: http://docs.oracle.com/javaee/5/api/javax/xml/stream/XMLStreamReader.html

I tried:

private void readXML() throws XMLStreamException {
    while(XMLStream.hasNext()) {
          if(next == XMLStreamReader.START_ELEMENT){
             System.out.println(XMLStream.getName());

But how do I get for example all the data of "YHOO" with all the correct numbers?

Thanks in advance!

Was it helpful?

Solution

The problem can solved by changing the Handler class of SAX. This is specific for a given XML file.

I found it from this document helped me to solve my problem. It seems SAX is very specific so you have to change the Handler to your needs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top