-
- def parse_rspec(self, rspec, namespaces={}):
- """
- parse rspec into etree
- """
- parser = etree.XMLParser(remove_blank_text=True)
- try:
- tree = etree.parse(rspec, parser)
- except IOError:
- # 'rspec' file doesnt exist. 'rspec' is proably an xml string
- try:
- tree = etree.parse(StringIO(rspec), parser)
- except:
- raise InvalidRSpec('Must specify a xml file or xml string. Received: ' + rspec )
- self.xml = tree.getroot()
- if namespaces:
- self.namespaces = namespaces
-
- def xpath(self, xpath):
- return this.xml.xpath(xpath, namespaces=self.namespaces)
-
- def add_attribute(self, elem, name, value):
- """
- Add attribute to specified etree element
- """
- opt = etree.SubElement(elem, name)
- opt.text = value