3 Replies Latest reply: Jun 19, 2008 3:50 PM by 666705 RSS

    Removing namespace prefixes

      I am familiar with the XmlOptions.setUseDefaultNamespace() to remove the namespace prefixes on the XML generated by my XMLBean. However, how do I specify which namespace prefix should be removed (if my XMLBean contains multiple namespace prefixes)? The docs for XmlOptions specify:

      "If this option is set, the saver will try to use the default namespace for the most commonly used URI. If it is not set the saver will always created named prefixes."

      Doing some testing, I have found that sometimes the correct namespace is being set as the default namespace. If my original document is:

      <ns1:a ...>
      <ns1:b ...>foo</b>
      <ns2:c ...>bar</c>

      if I use the xmlText(XmlOptions) method then I sometimes get back:

      <a ...>
      <b ...>foo</b>
      <ns2:c ...>bar</c>

      and sometimes get:

      <ns1:a ...>
      <ns1:b ...>foo</b>
      <c ...>bar</c>

      Any thoughts?
        • 1. Re: Removing namespace prefixes

          HashMap NamespaceMap = new HashMap();
          NamespaceMap.put("http://domain.com/dir1/subdir1/", "");
          NamespaceMap.put("http://domain.com/dir2/subdir2/", "");

          XmlOptions xo = new XmlOptions();


          • 2. Re: Removing namespace prefixes
            I have one question regarding removing namespace..

            I am trying to generate XML from XML Bean but i am getting namespace prefix in all my xml elements.

            For example
            <abc:Cutomer xmlns:abc="http://www.xyz.com/pqr>

            I don't have this namespace prefix in my XSD (imported in Weblogic workshop).

            Is there any way that I can remove this prefix from my xml elements?

            Also, I don't need xml namespace in my xml string.
            Is there any way that I can generate xml without having namespace?
            • 3. Re: Removing namespace prefixes
              I'm using xmlbeans in my project. I'm constructing xml using the xmlbeans
              generated sources from the XML Schema files. The server to which I'm
              sending the request doesn't recognize the namespace URI's or the prefixes.
              so, once the XML document is constructed, I'm trying to strip of the
              namespace URI's and prefixes using the below code and couldn't get it to

              Map m=
              new HashMap();

              http://www.abc.com/schemas/myproj/avail/2008/01, "");




              SampleRQDocument propAvailRQDoc = SampleRQDocument.Factory.*newInstance*


              The schemas are defined under 3 different namespaces.

              How can I remove the Namespace URI's and Prefixes after I construct the XML

              Next thing, when the server sends the response, the response doesn't include
              any Namespace URI or the prefixes. How can I embed the URI's and Prefixes in
              the response document after I receive it so, I can use XML Beans

              to bind the XML to the generated sources.

              I searched on google but couldn't find a suitable solution.

              Any help in this regard is greatly appreciated.