Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XML Element to string conversion returning null

843834Jun 16 2006 — edited Jul 12 2006
Hi,

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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 9 2006
Added on Jun 16 2006
5 comments
564 views