Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6723465

getLocalName() reports null for element nodes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 5.0
    • xml

      FULL PRODUCT VERSION :
      java version "1.5.0_03"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
      Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      org.w3c.dom.Node#getLocalName() returns null for element nodes. If I understand http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/Node.html#getLocalName() correctly, this is a bug.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See sample.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The element's name ('child' in the sample) should be returned.
      ACTUAL -
      null is returned.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.StringReader;

      import javax.xml.parsers.DocumentBuilder;
      import javax.xml.parsers.DocumentBuilderFactory;

      import org.w3c.dom.Document;
      import org.w3c.dom.Element;
      import org.w3c.dom.Node;
      import org.xml.sax.InputSource;


      public class GetLocalName
      {
       public static void main(String[] p_args) throws Exception
       {
        final StringReader l_sr;
        final DocumentBuilder l_bldr;
        final Document l_doc;
        final Node l_child;

        l_sr = new StringReader("<?xml version='1.0'?><root><child name='myname'/></root>");
        l_bldr = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        l_doc = l_bldr.parse(new InputSource(l_sr));

        l_child = l_doc.getDocumentElement().getChildNodes().item(0);

        if (!(l_child instanceof Element))
         throw new Exception("Must be an org.w3c.dom.Element.");

        if (!"child".equals(((Element)l_child).getTagName()))
         throw new Exception("Tag name must be \"child\"");

        if (l_child.getLocalName() == null)
         throw new Exception("Seems to be a bug. See http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/Node.html#getLocalName()");
       }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Get the element's name by other methods.

            joehw Joe Wang
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: