Ejemplo n.º 1
0
 def test_xpath_from_xml_node(self):
     xml_str = '<?xml version=\'1.0\' ?><test_item_name_matches_repeat ' \
               'id="repeat_child_name_matches_repeat">' \
               '<formhub><uuid>c911d71ce1ac48478e5f8bac99addc4e</uuid>' \
               '</formhub><gps><gps>-1.2625149 36.7924478 0.0 30.0</gps>' \
               '<info>Yo</info></gps><gps>' \
               '<gps>-1.2625072 36.7924328 0.0 30.0</gps>' \
               '<info>What</info></gps></test_item_name_matches_repeat>'
     clean_xml_str = xml_str.strip()
     clean_xml_str = re.sub(ur">\s+<", u"><", clean_xml_str)
     root_node = minidom.parseString(clean_xml_str).documentElement
     # get the first top-level gps element
     gps_node = root_node.firstChild.nextSibling
     self.assertEqual(gps_node.nodeName, u'gps')
     # get the info element within the gps element
     info_node = gps_node.getElementsByTagName(u'info')[0]
     # create an xpath that should look like gps/info
     xpath = xpath_from_xml_node(info_node)
     self.assertEqual(xpath, u'gps/info')
Ejemplo n.º 2
0
 def test_xpath_from_xml_node(self):
     xml_str = '<?xml version=\'1.0\' ?><test_item_name_matches_repeat ' \
               'id="repeat_child_name_matches_repeat">' \
               '<formhub><uuid>c911d71ce1ac48478e5f8bac99addc4e</uuid>' \
               '</formhub><gps><gps>-1.2625149 36.7924478 0.0 30.0</gps>' \
               '<info>Yo</info></gps><gps>' \
               '<gps>-1.2625072 36.7924328 0.0 30.0</gps>' \
               '<info>What</info></gps></test_item_name_matches_repeat>'
     clean_xml_str = xml_str.strip()
     clean_xml_str = re.sub(r">\s+<", u"><", clean_xml_str)
     root_node = minidom.parseString(clean_xml_str).documentElement
     # get the first top-level gps element
     gps_node = root_node.firstChild.nextSibling
     self.assertEqual(gps_node.nodeName, u'gps')
     # get the info element within the gps element
     info_node = gps_node.getElementsByTagName(u'info')[0]
     # create an xpath that should look like gps/info
     xpath = xpath_from_xml_node(info_node)
     self.assertEqual(xpath, u'gps/info')