| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Help!! XML with Java
Hi all!!
I badly need ur help.... what method in java can i used in getting the value in this element: <Wait>5</Wait>? I need to get the value of 5...I used DOM to access the XML...here is my code for this... public void readSgData(File oSgFile) throws Exception { Document document = null; DocumentBuilderFactory factory = DocumentBuilderFactory. newInstance(); try { DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.parse(oSgFile); NodeList oNodelist = document.getElementsByTagName("Wait"); for (int i=0; i< oNodelist.getLength();i++) { Node oNode = oNodelist.item(i); System.out.println("Node name: " + oNode.getNodeName()); if(oNode.getNodeType() == Node.ELEMENT_NODE) { Element oElem = (Element) oNode; System.err.println(oElem.toString()); } System.out.println("Node type: " + oNode.getNodeType()); System.out.println("Node value: " + oNode.getNodeValue()); } } catch (SAXException sxe) { // Error generated during parsing Exception x = sxe; if (sxe.getException() != null) x = sxe.getException(); x.printStackTrace(); } catch (ParserConfigurationException pce) { // Parser with specified options can't be built pce.printStackTrace(); } catch (IOException ioe) { // I/O error ioe.printStackTrace(); } catch(Exception e) { e.printStackTrace(); } return new EMSSgData(1, 1, 1); } and here is my xml file.... <?xml version="1.0" encoding="EUC-JP" ?> <message> <Wait>5</Wait> <Poll>5</Poll> <NotificationTimer>6</NotificationTimer> </message> thanx!!=) |
|
#2
|
|||
|
|||
|
try something like this
oNode.getFirstChild().getNodeValue(); |
![]() |
| Viewing: Tutorialized Forums > Web Design & Development > XML > Help!! XML with Java |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|