I have a XML file, for example:
<parent value="first">
<child>Bill</child>
</parent>
I want to get at output: value=first,child=Bill That means I need attribute from parrent element and value from child element.
I tried to do something like this:
List<Str> obj = new ArrayList<Str>();
NodeList nList = doc.getElementsByTagName("parent");
for (int i = 0; i < nList.getLength(); ++i) {
Element attrElement = (Element) nList.item(i);
NamedNodeMap map = attrElement.getAttributes();
for (int j = 0; j < map.getLength(); j++) {
Node attribute = map.item(j);
Node eNode = nList.item(j);
Element name = (Element) eNode;
obj.add(new Str(attribute.getNodeValue(), name.getElementsByTagName("child").item(0).getTextContent()));
}
}
In result i have Str with "null" values.