Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Spring Boot in Practice
this week in the
Spring
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Ron McLeod
Jeanne Boyarsky
Paul Clapham
Sheriffs:
Liutauras Vilda
Henry Wong
Devaka Cooray
Saloon Keepers:
Tim Moores
Stephan van Hulst
Tim Holloway
Al Hobbs
Carey Brown
Bartenders:
Piet Souris
Mikalai Zaikin
Himai Minh
Forum:
Beginning Java
Need Help --- Response XML Tag Value
Manikandan Sundaramoorthy
Greenhorn
Posts: 12
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
<?xml version="1.0"?> <service> <information> <Return_Msg>Hai</Return_Msg> </information> </service>
This is my response Xml file i need to read the "Return_Msg" tag value(Hai)
I'm trying with below code but its returning NullPointerException
try { URL url = new URL(requestUrl.toString()); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String inputLine; // System.out.println("-----RESPONSE START-----"); while ((inputLine = in.readLine()) != null) { System.out.println(inputLine); } in.close(); // System.out.println("-----RESPONSE END-----"); DocumentBuilderFactory factory =DocumentBuilderFactory.newInstance(); DocumentBuilder db = factory.newDocumentBuilder(); InputSource inStream = new InputSource(); inStream.setCharacterStream(new StringReader(inputLine)); Document doc = db.parse(inStream); //Document doc = docBuilder.parse (new File(inputLine)); // normalize text representation doc.getDocumentElement ().normalize (); NodeList listOfPersons = doc.getElementsByTagName("Information"); int totalPersons = listOfPersons.getLength(); for(int s=0; s<listOfPersons.getLength() ; s++){ Node firstPersonNode = listOfPersons.item(s); if(firstPersonNode.getNodeType() == Node.ELEMENT_NODE){ Element firstPersonElement = (Element)firstPersonNode; //------- NodeList firstNameList = firstPersonElement.getElementsByTagName("Return_Msg"); Element firstNameElement = (Element)firstNameList.item(0); NodeList textFNList = firstNameElement.getChildNodes(); System.out.println("Return Msg" + ((Node)textFNList.item(0)).getNodeValue().trim()); }//end of if clause }//end of for loop with s var } catch (Exception ex) { ex.printStackTrace(); }
i don't know how to parse the xml tag please help me
Campbell Ritchie
Marshal
Posts: 76110
362
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
XML is discussed on a different forum, but NullPointerExceptions here.
Please go through the stack trace and work out which object is null. It is impossible to solve that problem without the stack trace.
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Unable to get the correct data from the XML file
New to Java
help with web service to display xml file contents using netbeans
XML Parse
Storing SAX Parser data into MySql
More...