0

I have this response from SOAP:

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
 <env:Body>
  <env:Fault>
   <env:Code>
    <env:Value>env:Receiver</env:Value>
    <env:Subcode>
     <env:Value>-10</env:Value>
    </env:Subcode>
   </env:Code>
   <env:Reason>
    <env:Text xml:lang="en">10001069 - Item 804006 not active </env:Text>
   </env:Reason>
   <env:Detail>
    <Object xmlns="">17</Object>
    <ObjectIndex xmlns="">1</ObjectIndex>
    <Command xmlns="">AddObject</Command>
    <SessionID xmlns="">58711</SessionID>
   </env:Detail>
  </env:Fault>
 </env:Body>
</env:Envelope>

I'd Like to access/know tag Reason, like in python: print ObjectXML.Body.Reason.Text For instance, I want use dot notation for travel inside nodes. How I do it?.

Thanks in advance.

1 Answer 1

1

You can use cElement API to get the handle to XML tags in terms of python objects and then use the following activestate recipe to convert the XML to dict representation( Recommended only for smaller XML files, The code in the recipe might need some modifications).

import xml.etree.cElementTree as ElementTree
import XmlDictConfig as XmlDictConfig

if __name__ == "__main__":
  string_containing_my_xml = "read your XML into a string".
  root = ElementTree.parse(StringIO.StringIO(string_containing_my_xml)).getroot()
  xmldict = XmlDictConfig(root) // XmlDictConfig is available in activestate recipe.

http://code.activestate.com/recipes/410469-xml-as-dictionary/

Let me know in case anything is unclear to you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.