顯示了我的錯誤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>
should'value = 3D777' not'value ='3D777''? – karthikr
爲什麼有'OPTION = value = 3D1' ..?它是否正確..? – user2339071
感謝all..issue與標籤屬性 所以我在屬性中添加'',現在看起來問題是好的:-) –