<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="XXXXXXX">
<cuobject type-id="EmailSubscription" object-id="jjjil@gmail.com">
<object-attribute attribute-id="exported">true</object-attribute>
<object-attribute attribute-id="firstName">jjj</object-attribute>
<object-attribute attribute-id="lastName">jjj</object-attribute>
<object-attribute attribute-id="subscribed">true</object-attribute>
</cuobject>
<cuobject type-id="EmailSubscription" object-id="gggj@gmail.com">
<object-attribute attribute-id="exported">true</object-attribute>
<object-attribute attribute-id="firstName">ghh</object-attribute>
<object-attribute attribute-id="lastName">fhh</object-attribute>
<object-attribute attribute-id="subscribed">true</object-attribute>
</cuobject>
<cuobject type-id="EmailSubscription" object-id="mmm@gmail.com">
<object-attribute attribute-id="exported">true</object-attribute>
<object-attribute attribute-id="firstName">mmm</object-attribute>
<object-attribute attribute-id="lastName">mmm</object-attribute>
<object-attribute attribute-id="subscribed">true</object-attribute>
</cuobject>
</objects>
How to read this xml file in java (need to be done by using exported,firstName,lastName,...)? how do we do that? I am doing it like
NodeList nList = doc.getElementsByTagName("cuobject");
for (int temp = 0; temp < nList.getLength(); temp++)
{
Node nNode = nList.item(temp);
System.out.println("\nCurrent Element :" + nNode.getNodeName());
if (nNode.getNodeType() == Node.ELEMENT_NODE)
{
Element eElement = (Element) nNode;
String email = eElement.getAttribute("object-id");
String firstName = eElement.
getElementsByTagName("object-attribute").item(1).getTextContent();
String lastName = eElement.
getElementsByTagName("object-attribute").item(2).getTextContent();
String subscribed = eElement.
getElementsByTagName("object-attribute").item(3).getTextContent();
}
}