/scripts/galaxy_messaging/server/xml_helper.py

https://bitbucket.org/cistrome/cistrome-harvard/ · Python · 28 lines · 18 code · 3 blank · 7 comment · 5 complexity · e8489d08507007e8bb03a677d0715dbc MD5 · raw file

  1. #======= XML helper methods ====================================================
  2. import xml.dom.minidom
  3. def get_value( dom, tag_name ):
  4. '''
  5. This method extracts the tag value from the xml message
  6. '''
  7. nodelist = dom.getElementsByTagName( tag_name )[ 0 ].childNodes
  8. rc = ""
  9. for node in nodelist:
  10. if node.nodeType == node.TEXT_NODE:
  11. rc = rc + node.data
  12. return rc
  13. def get_value_index( dom, tag_name, dataset_id ):
  14. '''
  15. This method extracts the tag value from the xml message
  16. '''
  17. try:
  18. nodelist = dom.getElementsByTagName( tag_name )[ dataset_id ].childNodes
  19. except:
  20. return None
  21. rc = ""
  22. for node in nodelist:
  23. if node.nodeType == node.TEXT_NODE:
  24. rc = rc + node.data
  25. return rc