How to extract the string values "Hello" and "World" from the XML using Python 2.6
Question: I need to extract the strings "Hello" and "World" using Python 2.6. Please
advice.

    
    
    <Translate_Array_Request>
      <App_Id />
      <From>language-code</From>
      <Options>
        <Category xmlns="http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2" >string-value</Category>
        <Content Type xmlns="http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2">text/plain</ContentType>
        <Reserved Flags xmlns="http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2" />
        <State xmlns="http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2" >int-value</State>
        <Uri xmlns="http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2" >string-value</Uri>
        <User xmlns="http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2" >string-value</User>
      </Options>
      <Texts>
        <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">**Hello**</string>
        <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">**World**</string>
        </Texts>
      <To>language-code</To>
    </Translate_Array_Request>
    


Answer: There are multiple libraries in python that let you parse and extract data
from XML. One way would be to use the [ElementTree XML python
API](https://docs.python.org/2/library/xml.etree.elementtree.html). Assuming
the input is saved as a string `xml_data`, this is what you do:

    
    
    >>> import xml.etree.ElementTree as ET
    >>> root = ET.fromstring(xml_data)
    >>> texts = root.find('Texts')
    >>> for data in texts:
    ...     print data.text
    ...
    **Hello**
    **World**
    

