开发者

XML parsing In Blackberry

开发者 https://www.devze.com 2023-04-02 06:31 出处:网络
I want to parse the XML which I got from this url and I am doing parsing like this: connection = (HttpConnection)Connector.open(_url);

I want to parse the XML which I got from this url

and I am doing parsing like this:

connection = (HttpConnection)Connector.open(_url);
//Build Documents Based on the File
DocumentBuilderFactory factory = DocumentBuilderFactory.newInsta开发者_运维技巧nce();
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());
}


Your list.item(i) may have no childs so children will be null. Anyway, try to use parser from bb samples. Here is its code: XMLDemo code

0

精彩评论

暂无评论...
验证码 换一张
取 消