0 Replies Latest reply on Mar 30, 2006 8:31 PM by Kyle Duncan

    org.xml.sax.SAXParseException: The prefix

    Kyle Duncan Newbie

      org.xml.sax.SAXParseException: The prefix "xmlns" cannot be bound to any namespace explicitly; neither can the namespace for "xmlns" be bound to any prefix explicitly.

      I am trying to use the Apache xml security libraries together with JAXB and with JBoss's SAAJ implimentation, and I am frequently running into the 'xmlns' exception mentioned above. The full stack trace varies a great deal, so my including it wouldn't be of much help.

      However, none of my xml is defining a prefix with the 'xmlns' URI as its value, and I am not trying to use anything starting with 'xml' as a namespace prefix name.

      I am using JBoss 4.0.2, and I found the following items in source code that may be errors:

      Item 1:
      I ran into this when using SOAPMessage.writeTo to dump a document which I had added using SOAPBody.addDocument to System.out.

      In org.jboss.axis.encoding.SerializationContextImpl.java, Line 1082

      if (uri.equals(Constants.NS_URI_XMLNS))
       prefix = "xmlns";

      The code is iterating over attributes, and if their namespace URI was equal to the default URI, then it was adding the prefix 'xmlns'.

      My XML had something that looked like
      <MyTagName xmlns="myURI"/>

      So when it processed the attribute 'xmlns', it would go in with no prefix, and come out with the prefix 'xmlns', so that when it was finally output it looked like "xmlns:xmlns="myURI". Since namespace prefix names begginning with 'xml' are illegal, this caused me problems with every parser thereafter.

      Item 2:
      I ran into this when trying to parse a byte array containing my document into a Document object.

      In org.jboss.axis.message.SOAPElementAxisImpl.java, Line 721

      if (qname.startsWith("xmlns:") == false && qname.startsWith("xsi:") == false)
       qname = "xmlns:" + qname;

      The method is trying to convert SAX attributes to DOM attributes. If the attribute does not start with xmlns:, it gets padded with xmlns:.
      My attribute was, again, "xmlns='myURI'", which did not begin with 'xmlns:', so it was padded with a prefix. Again, the output looked like 'xmlns:xmlns="myURI"'. And again I had validation issues afterwards.

      After modifying these two items to no longer pad the default namespace attribute, I went without seeing that exception for a while... until now. I'm hitting a similar problem in a third place, and I haven't yet tracked down the root cause.

      Looking around online I find very little mention of the exception I keep hitting, and it's got me wondering if I'm doing something that's causing this?

      I generate a JAXB class based on a schema, I populate the required fields of the JAXB object and marshal it to a document. I then use Apache's xml security libraries to create the signature. I take that as a Document and add it to a SOAPBody in order to obtain a SOAPElement, which I pass from a client to a server via a webservice. There I reverse the whole operation. My latest encounter with this error has been during transforms while verifying the signature, and I'm still working on tracking the cause.

      JAXB has no problem with the schema. And most of the time parsers are having no problems with the XML it produces. But if I go through a conversion or two, say from JAXB to Document to SOAPElement, I frequently find problems.

      Has anyone else run into problems with their default namespace declaration getting mangled?

      Even if the issues I'm hitting really are bugs in other people's source rather than in mine (which might not be the case), I seem to be tripping every single one of the bugs, and there's no traffic about it online so somehow no one else is. Any hints regarding what might be causing me to trip these problems would be great- it's wasting days of development time, a few hours here, a few hours there.