} else {
// Namespace couldn't be resolved from any ancestor. If the namespace prefix is null then the
// element is simply in the undeclared default document namespace, which is fine. If it isn't null
// then a namespace prefix, that hasn't properly been declared, is being used.
if (namespacePrefix != null) {
throw new XMLParserException("Unable to resolve namespace prefix " + namespacePrefix
+ " found on element " + getNodeQName(domElement));
}
}
}
}
// Make sure all the attribute URIs are rooted here or have been rooted in an ancestor
NamedNodeMap attributes = domElement.getAttributes();
Node attributeNode;
for (int i = 0; i < attributes.getLength(); i++) {
namespacePrefix = null;
namespaceURI = null;
attributeNode = attributes.item(i);
// Shouldn't need this check, but just to be safe, we have it
if (attributeNode.getNodeType() != Node.ATTRIBUTE_NODE) {
continue;
}
namespacePrefix = attributeNode.getPrefix();
if (!DatatypeHelper.isEmpty(namespacePrefix)) {
// If it's the "xmlns" prefix then it is the namespace declaration,
// don't try to look it up and redeclare it
if (namespacePrefix.equals(XMLConstants.XMLNS_PREFIX)
|| namespacePrefix.equals(XMLConstants.XML_PREFIX)) {
continue;
}
// check to see if the namespace for the prefix has already been defined within the XML fragment
namespaceURI = lookupNamespaceURI(domElement, upperNamespaceSearchBound, namespacePrefix);
if (namespaceURI == null) {
namespaceURI = lookupNamespaceURI(upperNamespaceSearchBound, null, namespacePrefix);
if (namespaceURI == null) {
throw new XMLParserException("Unable to resolve namespace prefix " + namespacePrefix
+ " found on attribute " + getNodeQName(attributeNode) + " found on element "
+ getNodeQName(domElement));
}
appendNamespaceDeclaration(domElement, namespaceURI, namespacePrefix);