1

I am trying to parse the xml using the cElementTree library in python.But when i am trying to run the program it gives me error.

#!/usr/bin/python

import os
import xml.etree.ElementTree as etree

filename = "mood_ib_history_parameters_DEV.xml"
__currentlocation__ = os.getcwd()
__fullpath__ = os.path.join(__currentlocation__,filename)

tree = etree.parse(__fullpath__)
root = tree.getroot()

for child in root:
    print child.tag
    print child.attrib

Contents of mood_ib_history_parameters_DEV.xml:

<IB_Details>
   <hive_db>installbase</hive_db>
   <EDGE_HIVE_CONN>${EDGE_HIVE_CONN2}</EDGE_HIVE_CONN>
   <target_dir>somepath</target_dir>
   <to_email_alias>sr_ssot_dev@cisco.com</to_email_alias>
   <to_email_cc>hi@someone</to_email_cc>
   <from_email_alias>mail@google.com</from_email_alias>
   <dburl>jdbc:</dburl>
   <SQOOP_EDGE_CONN>${SQOOP_EDGE_NODE_1}</SQOOP_EDGE_CONN>
   <user_name>U</user_name>
   <password>P</password>
   <IB_log_table>IB_log</IB_log_table>
   <SR_DG_master_table>master</SR_DG_master_table>
   <SR_DG_table>governance_log</SR_DG_table>
</IB_Details>
AChampion
  • 29,683
  • 4
  • 59
  • 75
wandermonk
  • 6,856
  • 6
  • 43
  • 93
  • 1
    What error are you getting? You have a basic syntax error in your `for` loop as in it doesn't end in a `:` (I'm assuming the following prints are incorrectly indented just in your question). – AChampion Jan 15 '16 at 03:30
  • it is just giving me this output python xmlParser.py hive_db {} EDGE_HIVE_CONN {} target_dir {} to_email_alias {} to_email_cc {} from_email_alias {} dburl {} SQOOP_EDGE_CONN {} user_name {} password {} IB_log_table {} SR_DG_master_table {} SR_DG_table {} – wandermonk Jan 15 '16 at 03:34
  • You have no attributes, you have text, use `child.text` – AChampion Jan 15 '16 at 03:44

0 Answers0