Alex Cruise wrote:

I'm using the version of Xalan that comes with J2SE 1.4.2 and I'm having difficulty with namespaces.

I should probably quote some examples... :)

The XPath I'm searching for is '/soapenv:Body/ns1:getQuote'.

'soapenv' corresponds to 'http://schemas.xmlsoap.org/soap/envelope/';
'ns1' (a generated name obviously) corresponds to 'urn:xmethods-delayed-quotes'


I'm pretty sure that the prefixes in my XPath don't need to correspond to the prefixes in the request I'm trying to evaluate. Here's a request:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance";
        xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/";
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";
        xmlns:xsd="http://www.w3.org/1999/XMLSchema";
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";>
<SOAP-ENV:Body>
        <namesp1:getQuote xmlns:namesp1="urn:xmethods-delayed-quotes">
                <c-gensym3 xsi:type="xsd:string">
                SUNW
                </c-gensym3>
        </namesp1:getQuote>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

And here are a few snippets of the code I'm attempting to use to accomplish this:

    private class MyPrefixResolver implements PrefixResolver {
        public MyPrefixResolver( Map namespaceMap ) {
            _map = namespaceMap;
        }
        public String getNamespaceForPrefix(String prefix) {
            return (String)_map.get(prefix);
        }
        public String getNamespaceForPrefix(String prefix, Node context) {
            return getNamespaceForPrefix(prefix);
        }
        public String getBaseIdentifier() {
            return null;
        }
        public boolean handlesNullPrefixes() {
            return false;
        }
        private Map _map;
    }

(later...)

        _cachedXPathAPI = new CachedXPathAPI();
        Map namespaceMap = getNamespaceMap();
        if ( namespaceMap != null && !namespaceMap.isEmpty() ) {
            XPathContext context = _cachedXpathAPI.getXPathContext();
            context.setNamespaceContext(
                new MyPrefixResolver( namespaceMap ) );

(even later...)
NodeIterator i = _cachedXpathAPI.selectNodeIterator( doc, pattern );


TIA,

-0xe1a



Reply via email to