У меня нижеуказанный код.
import xml.dom.minidom
def get_a_document(name):
return xml.dom.minidom.parse(name)
doc = get_a_document("sources.xml")
sources = doc.childNodes[1]
for e in sources.childNodes:
if e.nodeType == e.ELEMENT_NODE and e.localName == "source":
for source in e.childNodes:
print source.localName
print source.nodeType
if source.nodeType == source.ELEMENT_NAME and source.localName == "language":
print source.localName
country = doc.createElement("country")
e.appendChild(country)
Я пытаюсь прочитать sources.xml и добавить страну элемента. Но я получаю ошибку ниже.
AttributeError: Text instance has no attribute 'ELEMENT_NAME'
Sources.xml выглядит так:
<?xml version="1.0" encoding="utf-8"?>
<!--sources.xml for multilingual, follows an ID range for different type of sources. Dailies sources are merged to this list-->
<sources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<source>
<id>1005001</id>
<language>Afar</language>
<status>active</status>
<tags>
<tag>language</tag>
</tags>
<title>Afar</title>
</source>
</sources>
Может кто-нибудь также предложить хороший учебник для библиотеки минидомов. Также, если бы вы могли предложить лучшую библиотеку Python xml, это будет здорово.
Спасибо
Bala