I want to get the Element-Node Sourrounding the Text-Node. According to this Element contains a Text-Node, vice versa a text-node should be surounded by a element-node.
I need the Element-node(openingTime) to get an attribute (day), but the NodeList (getChildNodes() called from the node openingHours) only gives me Text-Nodes with their parents being a Element-node (openingHours), but not the one surrounding the text-Node, but instead the one above. If anyone asks, i need to use DOM, because, as I have understood it, it is the fastest.
here is the XML:
<?xml version="1.0"?>
<stores>
<store name = "the Name of the Store">
<category>2nd Hand</category>
<locationAdress>sonstwo 18b, 12345 Bla</locationAdress>
<telephoneNumber>1234567812</telephoneNumber>
<openingHours>
<!-- Opening Hours, day permitted values: 1(Monday) - 7(Sunday) and 8 (workweek) -->
<openingTime day = "1">7:00 - 13:00 15:00 - 18:00</openingTime>
<openingTime day = "2">7:00 - 13:00 15:00 - 18:00</openingTime>
<openingTime day = "3">7:00 - 13:00 15:00 - 18:00</openingTime>
<openingTime day = "4">7:00 - 13:00 15:00 - 18:00</openingTime>
<openingTime day = "5">7:00 - 13:00 15:00 - 18:00</openingTime>
</openingHours>
</store>
</stores>
here is my java-code:
NodeList hoursList = storeElement.getElementsByTagName("openingHours").item(0).getChildNodes();
for (int y = 0; y < hoursList.getLength(); y++) {
Node hoursNode = hoursList.item(y);
boolean isElement = hoursNode.getNodeType() == Node.ELEMENT_NODE;
boolean hasChild = hoursNode.getChildNodes().getLength() != 0;
String nameParent = hoursNode.getParentNode().getNodeName();
boolean isElement is false, hasChild also false and String nameParent is openingHours.