Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
uttamtts
Posts: 144
Registered: ‎03-15-2011
My Device: blackberry smart phone
My Carrier: Airtel

Want help in Parsing the XML....

[ Edited ]

My XML is Like this

<xml_api_reply version="1"><weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
<current_conditions>
<condition data="Rain"/>
<temp_f data="48"/>
<temp_c data="9"/>
<humidity data="Humidity: 100%"/>
<icon data="/ig/images/weather/rain.gif"/>
<wind_condition data="Wind: N at 0 mph"/>
</current_conditions>

 This is the response i am getting from the URL : http://www.google.com/ig/api?weather=,,,50500000,30500000

And I am doing parsing is like ......

try{
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);
                        }
                        if(children.getAttributes().getNamedItem("data")!=null){
                            conditionData = children.getNodeValue();
                            System.out.println("++++++++++++++++++" + conditionData);
                           
                        } } } } }catch (Exception e) { // TODO: handle exception System.err.println("++++++++++++++++++"+e.getMessage()); }

 its getting the values null .... Can any one help me out ..

Thanks and regards

Please use plain text.