私はXMLDOMツリー構造と本当に混乱しています。
たとえば、私はこのXMLを持っています
<?xml version="1.0" encoding="UTF-8"?>
<Container>
<Group>
</Group>
<Group2>
</Group2>
</Container>
コンテナノードは2つの子だけで構成されるべきではありませんか?グループとグループ2?
File fXmlFile = new File("Test2.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
Node firstNode = doc.getDocumentElement();
if (firstNode.getNodeName().toString().equals("Container")) {
// Process container here
Container container = new Container();
System.out.println(firstNode.getChildNodes().getLength()); // why print out 5?
}