在解析 xml 文件时,我得到以下回溯
ParseError at /addxml/
junk after document element: line 13, column 2
Request Method: POST
Request URL: http://localhost:8000/addxml/
Django Version: 1.3.7
Exception Type: ParseError
Exception Value:
junk after document element: line 13, column 2
Exception Location: /root/Samples/DemoApp/DemoApp/views.py in addxml, line 98
Python Executable: /usr/bin/python
这是我的代码
if request.POST:
path = "{0}/app_name/filename.xml".format(settings.PROJECT_ROOT)
xmlDoc = open(path, 'r')
xmlDocData = xmlDoc.read()
xmlDocTree = etree.XML(xmlDocData)
下面的行给出了错误
xmlDocTree = etree.XML(xmlDocData)
<book>
<book_id>101</book_id>
<book_name>Python</book_name>
<publisher_name>Maxwell</publisher_name>
<author_id>1002</author_id>
<first_name>John</first_name>
<last_name>Dezosa</last_name>
<email>john@gmail.com</email>
<age>34</age>
</book>
<book>
<book_id>102</book_id>
<book_name>Django</book_name>
<publisher_name>Technical</publisher_name>
<author_id>1003</author_id>
<first_name>Josep</first_name>
<last_name>Raj</last_name>
<email>joseph@gmail.com</email>
<age>29</age>
</book>
谢谢