Example #1
0
    def load(self, source, prefixes=None, as_attribute=None, as_list=None, as_attribute_of_element=None, parser=None):
        """
        Load source into an Element instance

        Keyword arguments:
        source -- an XML string, a file path or a file object
        prefixes -- dictionnary of prefixes of the form {'prefix': 'ns'}
        as_attribute -- dictionary of element names to set as attribute of their parent
        as_list -- dictionary of element names to set into a list of their parent
        as_attribute_of_element -- dictionary of attribute names to set as attribute of their
        parent

        If any of those last three parameters are provided they will take
        precedence over those set on the Element and Attribute class.
        """
        if not parser and self.parser:
            parser = self.parser()
        elif not self.parser:
            from bridge.parser import get_first_available_parser

            parser = get_first_available_parser()
            self.parser = parser
            parser = parser()

        return parser.deserialize(
            source,
            prefixes=prefixes,
            as_attribute=as_attribute,
            as_list=as_list,
            as_attribute_of_element=as_attribute_of_element,
        )
Example #2
0
    def xml(self,
            indent=True,
            encoding=ENCODING,
            prefixes=None,
            omit_declaration=False):
        """
        Serializes this element as a string.

        :Parameters:
          - `indent`: pretty print the XML string (defaut: True)
          - `encoding`: encoding to use during the serialization process
          - `prefixes`: dictionnary of prefixes of the form {'prefix': 'ns'}
          - `omit_declaration`: prevent the result to start with the XML declaration

        :Returns:
          The XML string representing the current element.
        """
        from bridge.parser import get_first_available_parser
        parser = get_first_available_parser()()
        result = parser.serialize(self,
                                  indent=indent,
                                  encoding=encoding,
                                  prefixes=prefixes,
                                  omit_declaration=omit_declaration)
        del parser
        return result
Example #3
0
    def load(self, source, prefixes=None):
        """
        Load source into an Element instance

        :Parameters:
          - `source`: an XML string, a file path or a file object
          - `prefixes`: dictionnary of prefixes of the form {'prefix': 'ns'}
        """
        from bridge.parser import get_first_available_parser
        parser = get_first_available_parser()()
        result = parser.deserialize(source, prefixes=prefixes)
        del parser
        return result
Example #4
0
    def load(self, source, prefixes=None):
        """
        Load source into an Element instance

        :Parameters:
          - `source`: an XML string, a file path or a file object
          - `prefixes`: dictionnary of prefixes of the form {'prefix': 'ns'}
        """
        from bridge.parser import get_first_available_parser
        parser = get_first_available_parser()()
        result = parser.deserialize(source, prefixes=prefixes)
        del parser
        return result
Example #5
0
    def xml(self, indent=True, encoding=ENCODING, prefixes=None, omit_declaration=False):
        """
        Serializes this element as a string.

        :Parameters:
          - `indent`: pretty print the XML string (defaut: True)
          - `encoding`: encoding to use during the serialization process
          - `prefixes`: dictionnary of prefixes of the form {'prefix': 'ns'}
          - `omit_declaration`: prevent the result to start with the XML declaration

        :Returns:
          The XML string representing the current element.
        """
        from bridge.parser import get_first_available_parser
        parser = get_first_available_parser()()
        result = parser.serialize(self, indent=indent, encoding=encoding,
                                 prefixes=prefixes, omit_declaration=omit_declaration)
        del parser
        return result
Example #6
0
    def xml(self, indent=True, encoding=ENCODING, prefixes=None, omit_declaration=False, parser=None):
        """
        Serializes as a string this element

        Keyword arguments
        indent -- pretty print the XML string (defaut: True)
        encoding -- encoding to use during the serialization process
        prefixes -- dictionnary of prefixes of the form {'prefix': 'ns'}
        omit_declaration -- prevent the result to start with the XML declaration
        parser -- instance of an existing parser, if not provided the default one will be used
        """
        if not parser and self.parser:
            parser = self.parser()
        elif not self.parser:
            from bridge.parser import get_first_available_parser

            parser = get_first_available_parser()
            self.parser = parser
            parser = parser()

        return parser.serialize(
            self, indent=indent, encoding=encoding, prefixes=prefixes, omit_declaration=omit_declaration
        )