<?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>
Java でこの xml ファイルを読み取る方法 (exported,firstName,lastName,... を使用して行う必要があります)? どうやってそれをするのですか?みたいにやってます
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();
}
}