-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
6
-
x86
-
windows_xp
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.
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.