Exemple #1
0
def xml_out(qc, dest, stylesheet=None, indent=True):
    xqc = _xmlwrap.xml_quality_control()

    _xmldoc_out(xqc, qc)

    if isinstance(dest, basestring):
        fd = file(dest, "w")
    elif hasattr(dest, "write"):
        fd = dest
    else:
        raise TypeError, "invalid file object"

    try:
        filename = fd.name
    except AttributeError:
        filename = '<???>'

    fd.write('<?xml version="1.0" encoding="utf-8"?>\n')

    if stylesheet is not None:
        fd.write('<?xml-stylesheet type="application/xml" href="%s"?>\n' % \
            (stylesheet,))
    
    if indent is True:
        _indent(xqc._element)
    
    ET.ElementTree(xqc._element).write(fd, encoding="utf-8")
    
    if isinstance(dest, basestring):
        fd.close()
Exemple #2
0
    def close(self):
        root = self.__p.close()
        if root.tag != _root_tag:
            raise DBError, "unrecognized root element: " + root.tag

        xqc = _xmlwrap.xml_quality_control(root)
        _xmldoc_in(xqc, self.__qc)
Exemple #3
0
def xml_out(qc, dest, stylesheet=None, indent=True):
    xqc = _xmlwrap.xml_quality_control()

    _xmldoc_out(xqc, qc)

    if isinstance(dest, basestring):
        fd = file(dest, "w")
    elif hasattr(dest, "write"):
        fd = dest
    else:
        raise TypeError, "invalid file object"

    try:
        filename = fd.name
    except AttributeError:
        filename = '<???>'

    fd.write('<?xml version="1.0" encoding="utf-8"?>\n')

    if stylesheet != None:
        fd.write('<?xml-stylesheet type="application/xml" href="%s"?>\n' % \
            (stylesheet,))
    
    if indent is True:
        _indent(xqc._element)
    
    ET.ElementTree(xqc._element).write(fd, encoding="utf-8")
    
    if isinstance(dest, basestring):
        fd.close()
Exemple #4
0
    def close(self):
        root = self.__p.close()
        if root.tag != _root_tag:
            raise DBError, "unrecognized root element: " + root.tag

        xqc = _xmlwrap.xml_quality_control(root)
        _xmldoc_in(xqc, self.__qc)
Exemple #5
0
def xml_in(qc, src):
    doc = ET.parse(src)
    root = doc.getroot()
    if root.tag != _root_tag:
        raise DBError, "unrecognized root element: " + root.tag

    xqc = _xmlwrap.xml_quality_control(root)
    _xmldoc_in(xqc, qc)
Exemple #6
0
def xml_in(qc, src):
    doc = ET.parse(src)
    root = doc.getroot()
    if root.tag != _root_tag:
        raise DBError, "unrecognized root element: " + root.tag

    xqc = _xmlwrap.xml_quality_control(root)
    _xmldoc_in(xqc, qc)