def test_namespaces_to_string(): xml = XML.from_string( """<?xml version="1.0" encoding="UTF-8"?><robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="panda"><xacro:bamboo/></robot>""" ) xml_string = xml.to_string(prettify=True) assert b'xmlns:xacro="http://www.ros.org/wiki/xacro"' in xml_string assert b'<xacro:bamboo' in xml_string or b'<ns0:bamboo' in xml_string
def test_no_root_default_namespace(): xml = XML.from_string("""<?xml version="1.0"?> <main name="test-xml"> <item name="item1"><subitem /></item> <item xmlns="https://ethz.ch" name="item2"><subitem /></item> </main>""") assert not xml.root.attrib.get('xmlns') assert list(xml.root)[1].attrib['xmlns'] == 'https://ethz.ch' assert list(xml.root)[1].attrib['name'] == 'item2'
def test_nested_default_namespaces(): xml = XML.from_string("""<?xml version="1.0"?> <main xmlns="https://ita.arch.ethz.ch/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="test-xml"> <item name="item1"><subitem /></item> <item xmlns="https://ethz.ch" name="item2"><subitem /></item> </main>""") assert xml.root.attrib['xmlns'] == 'https://ita.arch.ethz.ch/' assert xml.root.attrib[ 'xmlns:xsi'] == 'http://www.w3.org/2001/XMLSchema-instance' # first element redefines default namespace assert list(xml.root)[1].attrib['xmlns'] == 'https://ethz.ch' assert list(xml.root)[1].attrib['name'] == 'item2'
def test_namespace_expansion(): xml = XML.from_string("""<?xml version="1.0"?> <main xmlns="https://ethz.ch" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="test-xml"> <item> <subitem xmlns:magic="https://sub.ethz.ch"> <magic:cat /> </subitem> </item> </main>""") assert xml.root.tag == '{https://ethz.ch}main' assert list(xml.root)[0].tag == '{https://ethz.ch}item' assert list(list(xml.root)[0])[0].tag == '{https://ethz.ch}subitem' assert list(list(list( xml.root)[0])[0])[0].tag == '{https://sub.ethz.ch}cat'
def from_srdf_string(cls, text, urdf_robot): xml = XML.from_string(text) return cls(xml.root, urdf_robot)
def _read_robot_name(self, robot_description): # TODO: Optimize this. We really don't need to parse the full URDF # only to read the robot's name (only used for local caching) xml = XML.from_string(robot_description) return xml.root.attrib['name']
def test_xml_to_string(sample_xml): xml = XML.from_string(sample_xml) strxml = xml.to_string('utf-8') assert strxml.startswith(b'<Tests>')
def test_xml_from_string(sample_xml): xml = XML.from_string(sample_xml) assert xml.root.tag == 'Tests'
def from_srdf_string(cls, text, robot_model): """Create an instance of semantics based on an SRDF string.""" xml = XML.from_string(text) return cls.from_xml(xml, robot_model)
def test_xml_to_pretty_string(sample_xml): xml = XML.from_string(sample_xml) prettyxml = xml.to_string(prettify=True) assert b"\n " in prettyxml
def test_xml_from_string(basic_xml): xml = XML.from_string(basic_xml) assert xml.root.tag == 'Tests'
def test_no_default_namespace(): xml = XML.from_string( """<?xml version="1.0"?><main name="test-xml"></main>""") assert not xml.root.attrib.get('xmlns') assert xml.root.attrib['name'] == 'test-xml'
def read_robot_name_and_uris_from_urdf(self, robot_description): xml = XML.from_string(robot_description) robot_name = xml.root.attrib['name'] uris = [mesh.attrib['filename'] for mesh in xml.root.iter('mesh') if mesh.attrib['filename'] != ''] return robot_name, uris