2011-09-05 122 views
1

我想解析XML至極i got from this urlXML解析黑莓

,我做解析這樣

connection = (HttpConnection)Connector.open(_url); 
//Build Documents Based on the File 
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
DocumentBuilder builder = factory.newDocumentBuilder(); 
builder.isValidating(); 
Document document = builder.parse(connection.openInputStream()); 
Element rootElement = document.getDocumentElement(); 
rootElement.normalize(); 
NodeList list = document.getElementsByTagName("current_conditions"); 
int check = list.getLength(); 
for(int i=0;i < check; i++){ 
    //NodeList children = list.item(i).getChildNodes(); 
    Node children = list.item(i).getFirstChild(); 
    String conditionData = new String(); 
    if (children.getNodeType()!= Node.TEXT_NODE){ 
     NamedNodeMap child = children.getAttributes(); 
     if(child.getNamedItem("data")!=null){ 
      conditionData = child.getNamedItem("data").getNodeValue(); 
      System.out.println("++++++++++++++++++++++++"+conditionData); 
     } 
    }   
} 

//displayNode(rootElement, 0); 

}catch (Exception e) { 
    // TODO: handle exception 
    System.err.println("++++++++++++++++++"+e.getMessage()); 
} 

請幫助...

+0

你在這裏有什麼問題?有什麼異常? – bharath

+0

它的價值是空的我沒有得到任何attributre的價值,你可以挖進代碼,並告訴我,我是否犯了錯誤 – BBdev

回答

1

你list.item(Ⅰ)沒有孩子,所以孩子將是空的。無論如何,嘗試使用bb示例中的解析器。這裏是它的代碼:XMLDemo code

+0

我已經做到了,它只給我的標籤名稱,但我沒有得到任何屬性值你能在代碼中的步驟,並告訴我,我是否犯了錯誤..... ..... – BBdev