[英]XML Parse ERROR : 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>
更改option
標簽中的value
屬性。 您需要用引號括住 id 的值 。
<option value='id'>XYZ</option>
要么
<option value="id">XYZ</option>
您可以使用任何一種報價。 單或雙。
供參考檢查: XML屬性
希望能幫助到你。:)
xml標記的所有屬性值都應用引號引起來。 因此,您的Value屬性應該用引號引起來
范例:
<person sex="female">
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.