use of org.loboevolution.html.node.NamedNodeMap in project LoboEvolution by LoboEvolution.
the class XPathNSResolverImpl method lookupNamespaceURI.
/**
* {@inheritDoc}
*/
@Override
public String lookupNamespaceURI(String prefix) {
String namespace = null;
if (prefix.equals("xml")) {
namespace = Constants.S_XMLNAMESPACEURI;
} else {
NodeType type;
while ((null != parent) && (null == namespace) && (((type = parent.getNodeType()) == NodeType.ELEMENT_NODE) || ((type = parent.getNodeType()) == NodeType.DOCUMENT_NODE) || (type == NodeType.ENTITY_REFERENCE_NODE))) {
if (type == NodeType.DOCUMENT_NODE) {
Document document = (Document) parent;
Element docelm = document.getDocumentElement();
if (docelm != null && docelm.getNodeName().indexOf(prefix.toUpperCase() + ":") == 0) {
return docelm.getNamespaceURI();
}
}
if (type == NodeType.ELEMENT_NODE) {
if (parent.getNodeName().indexOf(prefix.toUpperCase() + ":") == 0) {
return parent.getNamespaceURI();
}
NamedNodeMap nnm = ((Element) parent).getAttributes();
for (int i = 0; i < nnm.getLength(); i++) {
Node attr = nnm.item(i);
String aname = attr.getNodeName();
boolean isPrefix = aname.startsWith("xmlns:");
if (isPrefix || aname.equals("xmlns")) {
int index = aname.indexOf(':');
String p = isPrefix ? aname.substring(index + 1) : "";
if (p.equals(prefix)) {
namespace = attr.getNodeValue();
break;
}
}
}
}
parent = parent.getParentNode();
}
}
return namespace;
}
Aggregations