public static String resolveURI(final String baseURI, final Parent parent, String url) {

        if (!resolveURIs) {
            return url;
        }

        if (isRelativeURI(url)) {

            if (".".equals(url) || "./".equals(url)) {
                url = "";
            }

            if (url.startsWith("/") && baseURI != null) {
                String base = null;
                final int slashslash = baseURI.indexOf("//");
                final int nextslash = baseURI.indexOf("/", slashslash + 2);
                if (nextslash != -1) {
                    base = baseURI.substring(0, nextslash);
                }
                return formURI(base, url);
            }

            // Relative URI with parent
            if (parent != null && parent instanceof Element) {

                // Do we have an xml:base?
                String xmlbase = ((Element) parent).getAttributeValue("base", Namespace.XML_NAMESPACE);
                if (xmlbase != null && xmlbase.trim().length() > 0) {
                    if (isAbsoluteURI(xmlbase)) {
                        // Absolute xml:base, so form URI right now
                        if (url.startsWith("/")) {
                            // Host relative URI
                            final int slashslash = xmlbase.indexOf("//");
                            final int nextslash = xmlbase.indexOf("/", slashslash + 2);
                            if (nextslash != -1) {
                                xmlbase = xmlbase.substring(0, nextslash);
                            }
                            return formURI(xmlbase, url);
                        }
                        if (!xmlbase.endsWith("/")) {
                            // Base URI is filename, strip it off
                            xmlbase = xmlbase.substring(0, xmlbase.lastIndexOf("/"));
                        }
                        return formURI(xmlbase, url);
                    } else {
                        // Relative xml:base, so walk up tree
                        return resolveURI(baseURI, parent.getParent(), stripTrailingSlash(xmlbase) + "/" + stripStartingSlash(url));
                    }
                }
                // No xml:base so walk up tree
                return resolveURI(baseURI, parent.getParent(), url);

                // Relative URI with no parent (i.e. top of tree), so form URI
                // right now
            } else if (parent == null || parent instanceof Document) {
                return formURI(baseURI, url);
            }
        }

        return url;

    }
public static String resolveURI ( final String baseURI , final Parent parent , String url ) { if ( ! resolveURIs ) { return url ; } if ( isRelativeURI ( url ) ) { if ( "." . equals ( url ) || "./" . equals ( url ) ) { url = "" ; } if ( url . startsWith ( "/" ) && baseURI != null ) { String base = null ; final int slashslash = baseURI . indexOf ( "//" ) ; final int nextslash = baseURI . indexOf ( "/" , slashslash + 2 ) ; if ( nextslash != - 1 ) { base = baseURI . substring ( 0 , nextslash ) ; } return formURI ( base , url ) ; } if ( parent != null && parent instanceof Element ) { String xmlbase = ( ( Element ) parent ) . getAttributeValue ( "base" , Namespace . XML_NAMESPACE ) ; if ( xmlbase != null && xmlbase . trim ( ) . length ( ) > 0 ) { if ( isAbsoluteURI ( xmlbase ) ) { if ( url . startsWith ( "/" ) ) { final int slashslash = xmlbase . indexOf ( "//" ) ; final int nextslash = xmlbase . indexOf ( "/" , slashslash + 2 ) ; if ( nextslash != - 1 ) { xmlbase = xmlbase . substring ( 0 , nextslash ) ; } return formURI ( xmlbase , url ) ; } if ( ! xmlbase . endsWith ( "/" ) ) { xmlbase = xmlbase . substring ( 0 , xmlbase . lastIndexOf ( "/" ) ) ; } return formURI ( xmlbase , url ) ; } else { return resolveURI ( baseURI , parent . getParent ( ) , stripTrailingSlash ( xmlbase ) + "/" + stripStartingSlash ( url ) ) ; } } return resolveURI ( baseURI , parent . getParent ( ) , url ) ; } else if ( parent == null || parent instanceof Document ) { return formURI ( baseURI , url ) ; } } return url ; }
Resolve URI via base URL and parent element. Resolve URI based considering xml:base and
baseURI.

@param baseURI Base URI used to fetch the XML document
@param parent Parent element from which to consider xml:base
@param url URL to be resolved