A
A
Alexey2015-10-08 21:31:00
Django
Alexey, 2015-10-08 21:31:00

How to properly parse an external xml file in Django?

Hello, I'm doing a Django project. My task is to take the value from the form, find this value in the xml file and substitute id instead of the value. XML looks like this:

<ROWSET>
<ROW>
<element>Element_1</element>
<element_id>01</element_id>
<ROW>
<ROW>
<element>Element_2</element>
<element_id>02</element_id>
<ROW>
</ROWSET>

For parsing, I use the lxml library. The size of the xml file is about 2mb, it contains about 90000 lines (I don't know if it matters).
my code looks like this:
xml_file = etree.parse('/media/xml/example.xml')
find_data = etree.XPath("Element_1")
data_result = find_data(xml_file)

as a result, I get an error: Error reading file '/media/xml/example.xml': failed to load external entity "/media/xml/example.xml"
Please tell me what I'm doing wrong? And one more question along the way, how to get the value of the element_id element, if the value of element is known. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
belanchuk, 2015-12-21
@zago

lxml.de/tutorial.html#the-parse-function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question