elementtree sicil ad hatası:Bununla ad kayıt çalıştı
ET.register_namespace("inv", "http://www.stormware.cz/schema/version_2/invoice.xsd")
ama çalışmıyor:
Traceback (most recent call last):
File "C:\tutorial\temp_xml2.py", line 34, in module>
for listInvoice in root.findall('inv:invoiceHeader'):
File "C:\Python27\LIB\xml\etree\ElementTree.py", line 390, in findall
return ElementPath.findall(self, path, namespaces)
File "C:\Python27\LIB\xml\etree\ElementPath.py", line 293, in findall
return list(iterfind(elem, path, namespaces))
File "C:\Python27\LIB\xml\etree\ElementPath.py", line 259, in iterfind
token = next()
File "C:\Python27\LIB\xml\etree\ElementPath.py", line 83, in xpath_tokenizer
raise SyntaxError("prefix %r not found in prefix map" % prefix)
SyntaxError: prefix 'inv' not found in prefix map
>>>
bu nesi var?
Teşekkür Martinj
Denedim - 1 .:
for listInvoice in root.findall('inv:invoiceHeader', namespaces=dict(inv='http://www.stormware.cz/schema/version_2/invoice.xsd')):
invoiceHeader = listInvoice.find('inv:id', namespaces=dict(inv='http://www.stormware.cz/schema/version_2/invoice.xsd')).text
print invoiceHeader
Sonuç: (boş)
2 .:
nsmap=root.nsmap
print nsmap
Sonuç: AttributeError: ' Öğenin 'nesnesinin bir özelliği yoktur' ns haritası'
3 .:
for listInvoice in root.findall('.//{http://www.stormware.cz/schema/version_2/invoice.xsd}invoiceHeader'):
invoiceHeader = listInvoice.find('.//{http://www.stormware.cz/schema/version_2/invoice.xsd}id').text
print invoiceHeader
Sonuç: Tamam çalışır.
Ad alanlarını aynı anda kaydetme şansınız var mı? Sonra listInvoice.find ('inv: id') 'i kullanmak istiyorum.listesvoice.find (' .// {http://www.stormware.cz/schema/version_2/invoice.xsd} id 'yerine) .text (güzel kod ve okunması kolay)
Bu yanıt sizinkilere oldukça benzer görünüyor http://stackoverflow.com/a/12861866/735204 –