Issues Parsing Sub Nodes Java (YQL)



I am trying to parse a YQL Statement and retrieve the sub nodes / store the information in the sub nodes for a sandbox trading program. I can only get it to spit out all of the data at once currently and after searching and trying a few different methods I haven't made any progress. My query and code are:


YQL Query: http://ift.tt/TqU9VS*%20from%20yahoo.finance.quote%20where%20symbol%20in%20("MSFT"%2C"YHOO"%2C"AAPL"%2C"GOOG")&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys


Code:



NodeList resultList = docEle.getElementsByTagName("results");
for (int i = 0 ; i < resultList.getLength(); i++)
{
Node p = (Node) resultList.item(i);
if(p.getNodeType()==Node.ELEMENT_NODE)
{
//System.out.println("gets into nodetypes");
Element qi = (Element) p;
String tickerID = qi.getAttribute("quote");
System.out.println("tickerID: "+qi.getAttribute("quote")+" "+qi.getTagName()+" "+qi.getTextContent());
NodeList tickerList = qi.getChildNodes();
//System.out.println("NodeList tickerList: "+tickerList);
for(int j = 0; j < tickerList.getLength(); j++)
{
Node details = (Node) tickerList.item(j);
System.out.println("Node details: "+details);
if(details.getNodeType()==Node.ELEMENT_NODE)
{
Element di = (Element) details;
//System.out.println("Element di: "+di);
String detailsID = di.getAttribute("LastTradePriceOnly");
//System.out.println("String detailsID: "+detailsID);
}
}
//System.out.println(tickerID);
}
}

No comments:

Post a Comment