Priyan RockZ Priyan RockZ - 5 months ago 113
Java Question

XML Parse ERROR : org.xml.sax.SAXParseException

here shows my error

[Fatal Error] designations.xml:1:15: Open quote is expected for attribute "{1}" associated with an element type "value".
org.xml.sax.SAXParseException; systemId: file:/home/priyan/hr_openerp/XMLParserPro/src/com/priyan/designations.xml; lineNumber: 1; columnNumber: 15; Open quote is expected for attribute "{1}" associated with an element type "value".
at javax.xml.parsers.DocumentBuilder.parse(
at com.priyan.XmlParserMain.main(

here shows my code

public class XmlParserMain {
public static void main(String argv[]) {
try {
File fXmlFile = new File("/home/priyan/hr_openerp/XMLParserPro/src/com/priyan/designations.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);//ERROR COMES IN THIS LINE
System.out.println("Root element :"+ doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("staff");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
System.out.println("\nCurrent Element :" + nNode.getNodeName());
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
System.out.println("Designation: "+ eElement.getAttribute("OPTION"));
} catch (Exception e) {

here is my xml file which i'm going to parse

<OPTION value=3D777>3D Graphic Designer</OPTION>
<OPTION value=3D382>Account Executive</OPTION>
<OPTION value=3D108>Account Manager</OPTION>
<OPTION = value=3D1>Accountant</OPTION>
<OPTION = value=3D501>Accountant Inventory to Accountant = Payble
<OPTION value=3D304>Accountant Payable</OPTION>
<OPTION value=3D84>Accounts Assistant</OPTION>

Answer Source

Change the value attribute in the option tag. You need to have quotes surrounding the value of your id.

<option value='id'>XYZ</option>


<option value="id">XYZ</option>

You can use either of the quotations. Single or double.

For reference check: XML Attributes

Hope it helps.:)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download