'Export a list of fields in the resource as element tree
@param component: name of the component to lookup the fields
(None for primary table)
@param as_json: convert the output XML into JSON'

def export_fields(self, component=None, as_json=False):

    if (component is not None):
        c = self.components.get(component, None)
        if c:
            tree = c.export_fields()
            return tree
        else:
            raise AttributeError
    else:
        xml = current.xml
        tree = xml.get_fields(self.prefix, self.name)
        if as_json:
            return xml.tree2json(tree, pretty_print=True)
        else:
            return xml.tostring(tree, pretty_print=True)
