示例#1
0
def xml_out(inventory,
            dest,
            instr=0,
            modified_after=None,
            stylesheet=None,
            indent=True):
    xinventory = _xmlwrap.xml_Inventory()

    _xmldoc_out(xinventory, inventory, instr, modified_after)

    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(xinventory._element)

    ET.ElementTree(xinventory._element).write(fd, encoding="utf-8")

    if isinstance(dest, basestring):
        fd.close()
示例#2
0
    def close(self):
        root = self.__p.close()
        if root.tag != _root_tag:
            raise DBError, "unrecognized root element: " + root.tag

        xinventory = _xmlwrap.xml_Inventory(root)
        _xmldoc_in(xinventory, self.__inventory)
示例#3
0
    def close(self):
        root = self.__p.close()
        if root.tag != _root_tag:
            raise DBError, "unrecognized root element: " + root.tag

        xinventory = _xmlwrap.xml_Inventory(root)
        _xmldoc_in(xinventory, self.__inventory)
示例#4
0
def xml_out(inventory, dest, instr=0, modified_after=None, stylesheet=None, indent=True):
    xinventory = _xmlwrap.xml_Inventory()
    
    _xmldoc_out(xinventory, inventory, instr, modified_after)

    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(xinventory._element)
    
    ET.ElementTree(xinventory._element).write(fd, encoding="utf-8")
    
    if isinstance(dest, basestring):
        fd.close()
示例#5
0
def xml_in(inventory, src):
    doc = ET.parse(src)
    root = doc.getroot()
    if root.tag != _root_tag:
        raise DBError, "unrecognized root element: " + root.tag

    xinventory = _xmlwrap.xml_Inventory(root)
    _xmldoc_in(xinventory, inventory)
示例#6
0
def xml_in(inventory, src):
    doc = ET.parse(src)
    root = doc.getroot()
    if root.tag != _root_tag:
        raise DBError, "unrecognized root element: " + root.tag

    xinventory = _xmlwrap.xml_Inventory(root)
    _xmldoc_in(xinventory, inventory)