問題は、あなたがあなたのすべてのsets
内のリストを与えるdoc.getElementsByTagName("set")
を呼び出しているということです。以下は
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(xmlFile);
doc.getDocumentElement().normalize();
// Create a list of orders and sub elements
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
nList = doc.getElementsByTagName("order");
setList = doc.getElementsByTagName("set");
orders = new Order[nList.getLength()];
Node nNode = nList.item(i);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
temp = new Order();
// Populate order with details from XML
parseClientDetails(eElement);
// Add sets
parseSets();
temp.setSets(setArray);
orders[i] = temp;
}
...
private void parseSets() {
Node nNode;
Element element;
for (int c = 0; c < setList.getLength(); c++) {
nNode = setList.item(c);
element = (Element) nNode;
tempSet = new Set();
tempSet.setBandwidth(getValue("bandwidth", element));
tempSet.setCategory(getValue("category", element));
tempSet.setSet_package(getValue("package", element));
setArray.add(tempSet);
}
}
XML ...私のjavaですドキュメント全体代わりに、あなたはこのように、各順序でそれを呼び出す必要があります:
nList = doc.getElementsByTagName("order");
orders = new Order[nList.getLength()];
Node nNode = nList.item(i);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
//get the sets for the current order only
NodeList setList = eElement.getElementsByTagName("set");
//now process the sets
}