Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-2091

Namespace attributes not added as attributes when using TransformerIdentityImpl

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.6
    • 2.7.1
    • transformation
    • None
    • PatchAvailable

    Description

      Namespace attributes are not added as attributes to the resulting
      DOM tree when using TransformerIdentityImpl. The problem is, that
      the namespace-prefix feature is not set to true and therefore the
      namespace attributes are not added. This does not conform to the
      DOM spec saying that also namespace attributes may be handled as
      normal attributes.

      I will attach a patch which fixes the issue by calling

      reader.setFeature("http://xml.org/sax/features/namespace-prefixes",
      true);

      of the XMLReader.

      The following code shows the problem:

      The input XML document looks like this:

      <?xml version="1.0"?>
      <test xmlns:testns="http://testns.org" testns:testattr="3"/>

      And the code used to extract the namespace attributes is as follows:

      FileInputStream fis = new FileInputStream("test.xml");
      Transformer trfs = TransformerFactory.newInstance().newTransformer();
      StreamSource ss = new StreamSource(fis);
      DOMResult dr = new DOMResult();
      trfs.transform(ss, dr);
      Document doc = (Document)dr.getNode();
      Node node = doc.getFirstChild();
      System.out.println("First node: " + node.getLocalName());
      NamedNodeMap nodes = node.getAttributes();
      for (int i=0; i<nodes.getLength(); i++)

      { System.out.println(" Attribute: " + nodes.item(i).getLocalName()); }

      Finally, the the output looks like this:

      First node: test
      Attribute: testattr

      instead of the expected output:

      First node: test
      Attribute: testns
      Attribute: testattr

      Attachments

        1. TransformerIdentityImpl.java.diff
          0.8 kB
          Felix Röthenbacher
        2. Patch.txt
          3 kB
          Christine Li

        Issue Links

          Activity

            People

              jycli@ca.ibm.com Christine Li
              felix.roethenbacher@wyona.com Felix Röthenbacher
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: