2013-10-01 38 views
0

顯示了我的錯誤XML解析錯誤:這裏org.xml.sax.SAXParseException

[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 com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:251) 
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:300) 
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:205) 
    at com.priyan.XmlParserMain.main(XmlParserMain.java:20) 

在這裏展示我的代碼

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 
      doc.getDocumentElement().normalize(); 
      System.out.println("Root element :"+ doc.getDocumentElement().getNodeName()); 
      NodeList nList = doc.getElementsByTagName("staff"); 
      System.out.println("----------------------------"); 
      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) { 
      e.printStackTrace(); 
     } 
    } 
} 

這裏是我要去解析

我的XML文件
<designations> 
<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> 
<OPTION value=3D304>Accountant Payable</OPTION> 
<OPTION value=3D84>Accounts Assistant</OPTION> 
+1

should'value = 3D777' not'value ='3D777''? – karthikr

+2

爲什麼有'OPTION = value = 3D1' ..?它是否正確..? – user2339071

+0

感謝all..issue與標籤屬性 所以我在屬性中添加'',現在看起來問題是好的:-) –

回答

2

更改value屬性在option標籤。您需要有圍繞您的ID的值的報價。

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

OR

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

您可以使用該報價。單人或雙人。

僅供參考檢查:XML Attributes

希望它能幫助:)

+0

是否有可能禁用解析器的驗證? – Brain

1

xml標籤的所有屬性值應該用引號引起來。所以,你的價值屬性應與報價

例子:

<person sex="female"> 
    <firstname>Anna</firstname> 
    <lastname>Smith</lastname> 
</person> 
0

我也面臨這類問題。我的XML文件值僅用引號引起來。

File inputFile = new File(PropertiesFileHandler.getPropertyValue(PropertiesKeyConstants.LOG_PATH)+ fileIdentification +「。xml」); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); System.out.println(「input file is」+ inputFile); Document doc = dBuilder.parse(inputFile);

 doc.getDocumentElement().normalize(); 

     NodeList nList = doc.getElementsByTagName("item"); 

通過運行我的應用程序,在控制檯部分我收到此錯誤 輸入文件ISD的時間:\ RSS \ RSS_Status_Reportpool-1線程1.XML [致命錯誤] RSS_Status_Reportpool-1線程-1.xml:1:50:publicId和systemId之間需要空格。

+0

請正確格式化代碼。 –