Uploaded image for project: 'Axiom'
  1. Axiom
  2. AXIOM-497

Removal of namespace declaration breaks type attribute

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Cannot Reproduce
    • 1.2.13
    • None
    • Core Model, OM Mixins
    • None
    • Weblogic 12.2.1.3 version application server
    • Patch, Important
    • This issue is impacting our customers' business operations critically.

    Description

      When the following XML is converted to an OMElement, then written back out, the namespace prefix used by the xsi:type attribute refers to the incorrect namespace URI. That is because the local prefix mapping used in the type name reference is removed from the element that contains the type attribute during parsing.

      It appears to be caused by a null return value from the getNsBuilder method of AttributeCollector when it thinks the namespace declaration is redundant.

      Original XML:
      <ns1:A xmlns:ns1="urn:foo">
      <ns1:B xmlns:ns1="urn:bar">
      <ns2:C xmlns:ns1="urn:foo" xmlns:ns2="urn:bar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:TypeA"/>
      </ns1:B>
      </ns1:A>

      After conversion to OMElement, xsi:type name cannot be resolved because it is mapped to the wrong namespace URI:
      <ns1:A xmlns:ns1="urn:foo">
      <ns1:B xmlns:ns1="urn:bar">
      <ns2:C xmlns:ns2="urn:bar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:TypeA"/>
      </ns1:B>
      </ns1:A>

       

      Here's some sample code to reproduce the issue:

      ```

      System.out.println("Before StAX parsing:\n"+xmlString);

      try

      { java.io.StringReader stringReader = new java.io.StringReader(xmlString); javax.xml.stream.XMLInputFactory inputFactory = javax.xml.stream.XMLInputFactory.newInstance(); javax.xml.stream.XMLStreamReader streamReader = inputFactory.createXMLStreamReader(stringReader); org.apache.axiom.om.impl.builder.StAXOMBuilder builder = new org.apache.axiom.om.impl.builder.StAXOMBuilder(streamReader); xmlString = builder.getDocumentElement().toString(); }

      catch (Exception e)

      { System.out.println("Caught exception " + e); }

      System.out.println("After StAX parsing:\n"+xmlString);

      ```

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            Unifiers27 Unifiers Pega
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: