1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
public ArrayList getChildElementsByName(Element parentElt, String childName) throws XMLException {
if (parentElt == null) {
throw new XMLException("parentElt parameter cant be null");
}
if (childName == null) {
throw new XMLException("childName parameter cant be null");
}
ArrayList elements = new ArrayList();
NodeList nodes = parentElt.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if ((node.getNodeType() == Node.ELEMENT_NODE) && (node.getNodeName().equals(childName))) {
elements.add(node);
}
}
return elements;
}
public Element getFirstChildElementByName(Element parentElt, String childName) throws XMLException {
if (parentElt == null) {
throw new XMLException("parentElt parameter cant be null");
}
if (childName == null) {
throw new XMLException("childName parameter cant be null");
}
ArrayList elements = new ArrayList();
NodeList nodes = parentElt.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if ((node.getNodeType() == Node.ELEMENT_NODE) && (node.getNodeName().equals(childName))) {
return node;
}
}
} |
Partager