(self, name='Untitled Form', source=None)
Initialises an XFormBuilder instance

        If source is not given, initialises an empty XForm, and sets
        name/title to name parameter.

        If source is given then initialises from source, ignores name
        parameter. Assumes that source includes a data node.
Initialises an XFormBuilder instance
Initialises an XFormBuilder instance
def __init__(self, name='Untitled Form', source=None):
        """
        Initialises an XFormBuilder instance

        If source is not given, initialises an empty XForm, and sets
        name/title to name parameter.

        If source is given then initialises from source, ignores name
        parameter. Assumes that source includes a data node.
        """
        self.ns = {
            'h': "http://www.w3.org/1999/xhtml",
            'orx': "http://openrosa.org/jr/xforms",
            'x': "http://www.w3.org/2002/xforms",
            'xsd': "http://www.w3.org/2001/XMLSchema",
            'jr': "http://openrosa.org/javarosa",
            'jrm': "http://dev.commcarehq.org/jr/xforms",
        }
        strip_spaces = etree.XMLParser(remove_blank_text=True)
        if source is None:
            xmlns = 'http://openrosa.org/formdesigner/{}'.format(uuid.uuid4())
            self._etree = etree.XML(EMPTY_XFORM.format(name=name, xmlns=xmlns), parser=strip_spaces)
            self.ns['d'] = xmlns
            self._data = self._etree.xpath('./h:head/x:model/x:instance/d:data', namespaces=self.ns)[0]
        else:
            self._etree = etree.fromstring(source, parser=strip_spaces)
            # We don't know the data node's namespace, so we can't just fetch it with xpath.
            instance = self._etree.xpath('./h:head/x:model/x:instance', namespaces=self.ns)[0]
            self._data = [e for e in instance if e.tag == 'data'][0]
            self.ns['d'] = self._data.nsmap[None]
        self._model = self._etree.xpath('./h:head/x:model', namespaces=self.ns)[0]
        self._body = self._etree.xpath('./h:body', namespaces=self.ns)[0]
def __init__ ( self , name = 'Untitled Form' , source = None ) : self . ns = { 'h' : "http://www.w3.org/1999/xhtml" , 'orx' : "http://openrosa.org/jr/xforms" , 'x' : "http://www.w3.org/2002/xforms" , 'xsd' : "http://www.w3.org/2001/XMLSchema" , 'jr' : "http://openrosa.org/javarosa" , 'jrm' : "http://dev.commcarehq.org/jr/xforms" , } strip_spaces = etree . XMLParser ( remove_blank_text = True ) if source is None : xmlns = 'http://openrosa.org/formdesigner/{}' . format ( uuid . uuid4 ( ) ) self . _etree = etree . XML ( EMPTY_XFORM . format ( name = name , xmlns = xmlns ) , parser = strip_spaces ) self . ns [ 'd' ] = xmlns self . _data = self . _etree . xpath ( './h:head/x:model/x:instance/d:data' , namespaces = self . ns ) [ 0 ] else : self . _etree = etree . fromstring ( source , parser = strip_spaces ) # We don't know the data node's namespace, so we can't just fetch it with xpath. instance = self . _etree . xpath ( './h:head/x:model/x:instance' , namespaces = self . ns ) [ 0 ] self . _data = [ e for e in instance if e . tag == 'data' ] [ 0 ] self . ns [ 'd' ] = self . _data . nsmap [ None ] self . _model = self . _etree . xpath ( './h:head/x:model' , namespaces = self . ns ) [ 0 ] self . _body = self . _etree . xpath ( './h:body' , namespaces = self . ns ) [ 0 ]