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

org.w3c.dom.Document.getElementsByTagName() retrieves "null" in latest SUN JVM

XMLWordPrintable

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

      FULL PRODUCT VERSION :
      JDK release version "1.6.0_01".

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft XP Professional
      Version 2002
      Service Pack2


      A DESCRIPTION OF THE PROBLEM :
      When I try to use xml parser method such as "org.w3c.dom.Document.getElementsByTagName() ", it is retrieving "null" value for the tag. It is supposed to retrive the corresponding tag value.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Please refer the source code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      getElementsByTagName() must retrieve the value for the tag name specified (from the xml file).
      ACTUAL -
      getElementsByTagName() retrieves "null" from the xml file

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.File;
      import java.io.IOException;

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


      import org.xml.sax.SAXException;

      // Problem in getElementsByTagName()

      public class ParserTest {

      public static void main(String[] args) {

      // This file is present in the same package.
      String ConfigFilename = "Employee-Detail.xml";
      DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
      .newInstance();
      DocumentBuilder docBuilder = null;
      try {
      docBuilder = docBuilderFactory.newDocumentBuilder();
      } catch (ParserConfigurationException e) {
      e.printStackTrace();
      }
      org.w3c.dom.Document doc = null;
      try {
      doc = docBuilder.parse(new File(ConfigFilename));
      } catch (SAXException e) {
      e.printStackTrace();
      } catch (IOException e) {
      e.printStackTrace();
      }
      doc.getDocumentElement().normalize();
      // getElementsByTagName() retrieves "null" i.e it gives null value for the "Emp_Id" tag.
      String friendlyName = doc.getElementsByTagName("Emp_Id").item(0).toString();
              System.out.println(" "+friendlyName);
              

      }

      }




      // xml file for parsing

      /* "Employee-Detail.xml" file. Please save this file in a separate file and test it.

      <?xml version = "1.0" ?>
      <Employee-Detail>
      <Employee>
      <Emp_Id> E-001 </Emp_Id>
      <Emp_Name> Vinod </Emp_Name>
      <Emp_E-mail> ###@###.### </Emp_E-mail>
      </Employee>

      <Employee>
      <Emp_Id> E-002 </Emp_Id>
      <Emp_Name> Amit </Emp_Name>
      <Emp_E-mail> ###@###.### </Emp_E-mail>
      </Employee>

      <Employee>
      <Emp_Id> E-003 </Emp_Id>
      <Emp_Name> Deepak </Emp_Name>
      <Emp_E-mail> ###@###.### </Emp_E-mail>
      </Employee>

      </Employee-Detail>

      */





      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Do not know the cause.

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: