Attr attrNode = (Attr)attributes.getNamedItem("xml:base");
if (attrNode != null) {
String uri = attrNode.getNodeValue();
if (uri.length() != 0 ) {// attribute value is always empty string
try {
uri = new URI(uri).toString();
}
catch (com.sun.org.apache.xerces.internal.util.URI.MalformedURIException e) {
// This may be a relative URI.
// Make any parentURI into a URI object to use with the URI(URI, String) constructor
String parentBaseURI = (this.ownerNode != null) ? this.ownerNode.getBaseURI() : null;
if (parentBaseURI != null){
try{
uri = new URI(new URI(parentBaseURI), uri).toString();
}
catch (com.sun.org.apache.xerces.internal.util.URI.MalformedURIException ex){
// This should never happen: parent should have checked the URI and returned null if invalid.
return null;
}
return uri;
}
return null;
}
return uri;
}
}
}
// 2.the base URI of the element's parent element within the
// document or external entity, if one exists
// 3. the base URI of the document entity or external entity
// containing the element
// ownerNode serves as a parent or as document
String baseURI = (this.ownerNode != null) ? this.ownerNode.getBaseURI() : null ;
//base URI of parent element is not null
if(baseURI != null){
try {
//return valid absolute base URI
return new URI(baseURI).toString();
}
catch (com.sun.org.apache.xerces.internal.util.URI.MalformedURIException e){
return null;
}
}