XML Element to string conversion returning null
843834Jun 16 2006 — edited Jul 12 2006Hi,
When i try to convert XML Element to string using toString() API, it returns something like [device: null] where device is element tag.
Code is as follows -
Document xmlDoc;
DOMParser parser = (DOMParser)Class.forName("org.apache.xerces.parsers.DOMParser").newInstance();
parser.setFeature( "http://apache.org/xml/features/dom/defer-node-expansion", true );
parser.parse(new InputSource(new StringReader(tableStr)));
xmlDoc = parser.getDocument();
Element root = xmlDoc.getDocumentElement();
NodeList nodeList = root.getElementsByTagName("device");
Element deviceNode = (Element)nodeList.item(nodeList.getLength()-1);
System.out.println(deviceNode.toString()); //prints [device: null] ????
System.out.println(deviceNode.getAttribute("ipAddress")); //prints correct ip address
Any idea why i am getting [device: null] when trying to convert Element to String though attribute value is retrieved.
Thanks,
Deepak