XML Читать с Python и минидомом - PullRequest
0 голосов
/ 17 июня 2020

Мне нужно получить определенные c данные в дереве узлов. Как вы можете видеть на изображении, мне нужно получить данные клиента, такие как номер, я пытаюсь ввести узел за узлом, но это не так. сработало

enter image description here

<cac:AccountingCustomerParty>
<cac:Party>
<cac:PartyIdentification>
<cbc:ID schemeID="6">20530131981</cbc:ID>
</cac:PartyIdentification>
<cac:PartyLegalEntity>
<cbc:RegistrationName>
<![CDATA[ ASUAREZC CONSTRUCTORA EMPRESA INDIVIDUAL DE RESPONSABILIDAD LIMITADA ]]>
</cbc:RegistrationName>
<cac:RegistrationAddress>
<cbc:ID>150101</cbc:ID>
<cac:AddressLine>
<cbc:Line>
<![CDATA[ LT. 10 MZ. BY URB. MIRAFLORES COUNTRY CLUB - PIURA PIURA CASTILLA ]]>
</cbc:Line>
</cac:AddressLine>
<cac:Country>
<cbc:IdentificationCode>PE</cbc:IdentificationCode>
</cac:Country>
</cac:RegistrationAddress>
</cac:PartyLegalEntity>
</cac:Party>
</cac:AccountingCustomerParty>

код

from xml.dom import minidom

doc = minidom.parse(ficheroRuta)

   customer = (((doc.getElementsByTagName("cac:AccountingCustomerParty")[0]).getElementsByTagName("cac:Party")[0]).getElementsByTagName("cac:PartyIdentification")[0]).getElementsByTagName("cbc:ID")[0]

   print(customer.firstChild.data)

ошибка

AttributeError: 'NoneType' object has no attribute 'data'
...