log.trace("Starting to unmarshall DOM element {}", XMLHelper.getNodeQName(domElement));
}
checkElementIsTarget(domElement);
XMLObject xmlObject = buildXMLObject(domElement);
if (log.isTraceEnabled()) {
log.trace("Unmarshalling attributes of DOM Element {}", XMLHelper.getNodeQName(domElement));
}
NamedNodeMap attributes = domElement.getAttributes();
Node attribute;
for (int i = 0; i < attributes.getLength(); i++) {
attribute = attributes.item(i);
// These should allows be attribute nodes, but just in case...
if (attribute.getNodeType() == Node.ATTRIBUTE_NODE) {
unmarshallAttribute(xmlObject, (Attr) attribute);
}
}
if (log.isTraceEnabled()) {
log.trace("Unmarshalling other child nodes of DOM Element {}", XMLHelper.getNodeQName(domElement));
}
Node childNode = domElement.getFirstChild();
while (childNode != null) {
if (childNode.getNodeType() == Node.ATTRIBUTE_NODE) {
unmarshallAttribute(xmlObject, (Attr) childNode);
} else if (childNode.getNodeType() == Node.ELEMENT_NODE) {
unmarshallChildElement(xmlObject, (Element) childNode);
} else if (childNode.getNodeType() == Node.TEXT_NODE
|| childNode.getNodeType() == Node.CDATA_SECTION_NODE) {
unmarshallTextContent(xmlObject, (Text) childNode);
}
childNode = childNode.getNextSibling();
}
xmlObject.setDOM(domElement);
return xmlObject;
}