示例#1
0
 def test_annotate_with_XMLNS_with_Element_as_input(self):
     expected = '<root xmlns:p="http://test.com/schemas/f.xsd">' + \
                 '<p:c1><p:gc1>test</p:gc1></p:c1></root>'
     root_node = ET.Element("root")
     c1_node = ET.SubElement(root_node, "c1")
     gc1_node = ET.SubElement(c1_node, "gc1")
     gc1_node.text = "test"
     xmlutils.annotate_with_XMLNS(root_node, 'p',
                                  'http://test.com/schemas/f.xsd')
     self.assertEqual(expected, xmlutils.DOM_node_to_XML(root_node, False))
示例#2
0
 def test_annotate_with_XMLNS_with_Element_as_input(self):
     expected = '<root xmlns:p="http://test.com/schemas/f.xsd">' + \
                 '<p:c1><p:gc1>test</p:gc1></p:c1></root>'
     root_node = ET.Element("root")
     c1_node = ET.SubElement(root_node, "c1")
     gc1_node = ET.SubElement(c1_node, "gc1")
     gc1_node.text = "test"
     xmlutils.annotate_with_XMLNS(root_node, 'p',
                                  'http://test.com/schemas/f.xsd')
     self.assertEqual(expected, xmlutils.DOM_node_to_XML(root_node, False))
示例#3
0
    def to_XML(self, xml_declaration=True, xmlns=True):
        """
        Dumps object fields to an XML-formatted string. The 'xml_declaration'
        switch  enables printing of a leading standard XML line containing XML
        version and encoding. The 'xmlns' switch enables printing of qualified
        XMLNS prefixes.

        :param XML_declaration: if ``True`` (default) prints a leading XML
            declaration line
        :type XML_declaration: bool
        :param xmlns: if ``True`` (default) prints full XMLNS prefixes
        :type xmlns: bool
        :returns: an XML-formatted string

        """
        root_node = self._to_DOM()
        if xmlns:
            xmlutils.annotate_with_XMLNS(root_node, FORECAST_XMLNS_PREFIX, FORECAST_XMLNS_URL)
        return xmlutils.DOM_node_to_XML(root_node, xml_declaration)
示例#4
0
    def to_XML(self, xml_declaration=True, xmlns=True):
        """
        Dumps object fields to an XML-formatted string. The 'xml_declaration'
        switch  enables printing of a leading standard XML line containing XML
        version and encoding. The 'xmlns' switch enables printing of qualified
        XMLNS prefixes.

        :param XML_declaration: if ``True`` (default) prints a leading XML
            declaration line
        :type XML_declaration: bool
        :param xmlns: if ``True`` (default) prints full XMLNS prefixes
        :type xmlns: bool
        :returns: an XML-formatted string

        """
        root_node = self._to_DOM()
        if xmlns:
            xmlutils.annotate_with_XMLNS(root_node, OZONE_XMLNS_PREFIX,
                                         OZONE_XMLNS_URL)
        return xmlutils.DOM_node_to_XML(root_node, xml_declaration)