[Fatal Error] :3:13: Open quote is expected for attribute "{1}" associated with an element type "id".

用DOM解析XML时出现了如下错误:

[Fatal Error] :3:13: Open quote is expected for attribute "{1}" associated with an  element type  "id".
org.xml.sax.SAXParseException: Open quote is expected for attribute "{1}" associated with an  element type  "id".
 at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:246)
 at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
 at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)
 at com.xml.DOMDemo.parseDomXML(DOMDemo.java:26)
 at com.xml.DOMDemo.main(DOMDemo.java:14)

检查后发现我的xml文件是这样写的

<?xml version="1.0" encoding="UTF-8"?>
<message>
     <person id=1>
        <name>jerry</name>
        <age>18</age>
        <sex>男</sex>
    </person>
    <person id=2>
       <name>Aimi</name>
      <age>20</age>
      <sex>女</sex>
   </person>
</message>

错误就在于,xml元素的开始标签的属性必须用双引号括起来

改为:

<person id="1">

<person id="2">

上一篇:pycharm svn服务器访问不了的问题。


下一篇:KnockoutJS 3.X API 第六章 组件(4) 自定义元素