<p>I am receiving SOAP requests from a client that uses the Axis 1.4 libraries. The requests have the following form:</p>

<pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;soapenv:Body&gt;
    &lt;PlaceOrderRequest xmlns="http://example.com/schema/order/request"&gt;
      &lt;order&gt;
        &lt;ns1:requestParameter xmlns:ns1="http://example.com/schema/common/request"&gt;
          &lt;ns1:orderingSystemWithDomain&gt;
            &lt;ns1:orderingSystem&gt;Internet&lt;/ns1:orderingSystem&gt;
            &lt;ns1:domainSign&gt;2&lt;/ns1:domainSign&gt;
          &lt;/ns1:orderingSystemWithDomain&gt;
        &lt;/ns1:requestParameter&gt;
        &lt;ns2:directDeliveryAddress ns2:addressType="0" ns2:index="1" 
                                   xmlns:ns2="http://example.com/schema/order/request"&gt;
          &lt;ns3:address xmlns:ns3="http://example.com/schema/common/request"&gt;
            &lt;ns4:zipcode xmlns:ns4="http://example.com/schema/common"&gt;12345&lt;/ns4:zipcode&gt;
            &lt;ns5:city xmlns:ns5="http://example.com/schema/common"&gt;City&lt;/ns5:city&gt;
            &lt;ns6:street xmlns:ns6="http://example.com/schema/common"&gt;Street&lt;/ns6:street&gt;
            &lt;ns7:houseNum xmlns:ns7="http://example.com/schema/common"&gt;1&lt;/ns7:houseNum&gt;
            &lt;ns8:country xmlns:ns8="http://example.com/schema/common"&gt;XX&lt;/ns8:country&gt;
          &lt;/ns3:address&gt;
[...]
</code></pre>

<p>As you can see, several prefixes are defined for the same namespace, e.g. the namespace <a href="http://example.com/schema/common" rel="noreferrer">http://example.com/schema/common</a> has the prefixes ns4, ns5, ns6, ns7 and ns8. Some long requests define several hundred prefixes for the same namespace.</p>

<p>This causes a problem with the <a href="http://saxon.sourceforge.net/" rel="noreferrer">Saxon</a> XSLT processor, that I use to transform the requests. Saxon limits the the number of different prefixes for the same namespace to 255 and throws an exception when you define more prefixes.</p>

<p>Can Axis 1.4 be configured to define smarter prefixes, so that there is only one prefix for each namespace?</p>

[{'answer_id': 179495, 'author': 'Ian McLaird', 'author_id': 18796, 'author_profile': 'https://Stackoverflow.com/users/18796', 'pm_score': 2, 'selected': False, 'text': '<p>I have the same issue.  For the moment, I\'ve worked around it by writing a BasicHandler extension, and then walking the SOAPPart myself and moving the namespace reference up to a parent node.  I don\'t <em>like</em> this solution, but it does seem to work.</p>\n\n<p>I really hope somebody comes along and tells us what we have to do.</p>\n\n<p><strong><em>EDIT</em></strong></p>\n\n<p>This is way too complicated, and like I said, I don\'t like it at all, but here we go.  I actually broke the functionality into a few classes (This wasn\'t the only manipulation that we needed to do in that project, so there were other implementations)  I really hope that somebody can fix this soon.  This uses dom4j to process the XML passing through the SOAP process, so you\'ll need dom4j to make it work.</p>\n\n<pre><code>public class XMLManipulationHandler extends BasicHandler {\n    private static Log log = LogFactory.getLog(XMLManipulationHandler.class);\n    private static List processingHandlers;\n\n    public static void setProcessingHandlers(List handlers) {\n        processingHandlers = handlers;\n    }\n\n    protected Document process(Document doc) {\n        if (processingHandlers == null) {\n            processingHandlers = new ArrayList();\n            processingHandlers.add(new EmptyProcessingHandler());\n        }\n        log.trace(processingHandlers);\n        treeWalk(doc.getRootElement());\n        return doc;\n    }\n\n    protected void treeWalk(Element element) {\n        for (int i = 0, size = element.nodeCount(); i &lt; size; i++) {\n            Node node = element.node(i);\n            for (int handlerIndex = 0; handlerIndex &lt; processingHandlers.size(); handlerIndex++) {\n                ProcessingHandler handler = (ProcessingHandler) processingHandlers.get(handlerIndex);\n                handler.process(node);\n            }\n            if (node instanceof Element) {\n                treeWalk((Element) node);\n            }\n        }\n    }\n\n    public void invoke(MessageContext context) throws AxisFault {\n        if (!context.getPastPivot()) {\n            SOAPMessage message = context.getMessage();\n            SOAPPart soapPart = message.getSOAPPart();\n            ByteArrayOutputStream baos = new ByteArrayOutputStream();\n\n            try {\n                message.writeTo(baos);\n                baos.flush();\n                baos.close();\n\n                ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());\n                SAXReader saxReader = new SAXReader();\n                Document doc = saxReader.read(bais);\n                doc = process(doc);\n                DocumentSource ds = new DocumentSource(doc);\n                soapPart.setContent(ds);\n                message.saveChanges();\n            } catch (Exception e) {\n                throw new AxisFault("Error Caught processing document in XMLManipulationHandler", e);\n            }\n        }\n    }\n}\n</code></pre>\n\n<pre><code>public interface ProcessingHandler {\n    public Node process(Node node);\n}\n</code></pre>\n\n<pre><code>public class NamespaceRemovalHandler implements ProcessingHandler {\n    private static Log log = LogFactory.getLog(NamespaceRemovalHandler.class);\n    private Namespace namespace;\n    private String targetElement;\n    private Set ignoreElements;\n\n    public NamespaceRemovalHandler() {\n        ignoreElements = new HashSet();\n    }\n\n    public Node process(Node node) {\n        if (node instanceof Element) {\n            Element element = (Element) node;\n            if (element.isRootElement()) {\n                // Evidently, we never actually see the root node when we\'re called from\n                // SOAP...\n            } else {\n                if (element.getName().equals(targetElement)) {\n                    log.trace("Found the target Element.  Adding requested namespace");\n                    Namespace already = element.getNamespaceForURI(namespace.getURI());\n                    if (already == null) {\n                        element.add(namespace);\n                    }\n                } else if (!ignoreElements.contains(element.getName())) {\n                    Namespace target = element.getNamespaceForURI(namespace.getURI());\n                    if (target != null) {\n                        element.remove(target);\n                        element.setQName(new QName(element.getName(), namespace));\n                    }\n                }\n\n                Attribute type = element.attribute("type");\n                if (type != null) {\n                    log.trace("Replacing type information: " + type.getText());\n                    String typeText = type.getText();\n                    typeText = typeText.replaceAll("ns[0-9]+", namespace.getPrefix());\n                    type.setText(typeText);\n                }\n            }\n        }\n\n        return node;\n    }\n\n    public Namespace getNamespace() {\n        return namespace;\n    }\n\n    public void setNamespace(Namespace namespace) {\n        this.namespace = namespace;\n    }\n\n    /**\n     * @return the targetElement\n     */\n    public String getTargetElement() {\n        return targetElement;\n    }\n\n    /**\n     * @param targetElement the targetElement to set\n     */\n    public void setTargetElement(String targetElement) {\n        this.targetElement = targetElement;\n    }\n\n    /**\n     * @return the ignoreElements\n     */\n    public Set getIgnoreElements() {\n        return ignoreElements;\n    }\n\n    /**\n     * @param ignoreElements the ignoreElements to set\n     */\n    public void setIgnoreElements(Set ignoreElements) {\n        this.ignoreElements = ignoreElements;\n    }\n\n    public void addIgnoreElement(String element) {\n        this.ignoreElements.add(element);\n    }\n}\n</code></pre>\n\n<p>No warranty, etc, etc.</p>\n'}, {'answer_id': 185432, 'author': 'Stephen Denne', 'author_id': 11721, 'author_profile': 'https://Stackoverflow.com/users/11721', 'pm_score': 1, 'selected': False, 'text': '<p>Alter your client\'s wsdd to set <code>enableNamespacePrefixOptimization</code> to <code>true</code></p>\n\n<pre><code>&lt;globalConfiguration &gt;\n  &lt;parameter name="enableNamespacePrefixOptimization" value="true"/&gt;\n</code></pre>\n'}, {'answer_id': 5649242, 'author': 'Pica Creations', 'author_id': 706035, 'author_profile': 'https://Stackoverflow.com/users/706035', 'pm_score': 2, 'selected': False, 'text': '<p>For the Request I use this to remove namespaces types:</p>\n\n<pre><code>String endpoint = "http://localhost:5555/yourService";\n\n// Parameter to be send\nInteger secuencial = new Integer(11);  // 0011\n\n// Make the call\nService  service = new Service();\n\nCall call = (Call) service.createCall();\n\n// Disable sending Multirefs\ncall.setOption( org.apache.axis.AxisEngine.PROP_DOMULTIREFS, new java.lang.Boolean( false) ); \n\n// Disable sending xsi:type\ncall.setOption(org.apache.axis.AxisEngine.PROP_SEND_XSI, new java.lang.Boolean( false));  \n\n// XML with new line\ncall.setOption(org.apache.axis.AxisEngine.PROP_DISABLE_PRETTY_XML, new java.lang.Boolean( false)); \n\n// Other Options. You will not need them\ncall.setOption(org.apache.axis.AxisEngine.PROP_ENABLE_NAMESPACE_PREFIX_OPTIMIZATION, new java.lang.Boolean( true)); \ncall.setOption(org.apache.axis.AxisEngine.PROP_DOTNET_SOAPENC_FIX, new java.lang.Boolean( true));\n\ncall.setTargetEndpointAddress(new java.net.URL(endpoint));\ncall.setSOAPActionURI("http://YourActionUrl");//Optional\n\n// Opertion Name\n//call.setOperationName( "YourMethod" );\ncall.setOperationName(new javax.xml.namespace.QName("http://yourUrl", "YourMethod"));      \n\n// Do not send encoding style\ncall.setEncodingStyle(null);\n\n// Do not send xmlns in the xml nodes\ncall.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);\n\n/////// Configuration of namespaces\norg.apache.axis.description.OperationDesc oper;\norg.apache.axis.description.ParameterDesc param;\noper = new org.apache.axis.description.OperationDesc();\noper.setName("InsertaTran");\nparam = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("http://yourUrl", "secuencial"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "int"), int.class, false, false);\noper.addParameter(param);\n\noper.setReturnType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "int"));\noper.setReturnClass(int.class);\noper.setReturnQName(new javax.xml.namespace.QName("http://yourUrl", "yourReturnMethod"));\noper.setStyle(org.apache.axis.constants.Style.WRAPPED);\noper.setUse(org.apache.axis.constants.Use.LITERAL);\n\ncall.setOperation(oper);\n\nInteger ret = (Integer) call.invoke( new java.lang.Object [] \n            { secuencial });\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/62490', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5035/']