"""
# PART I - Imports/Configuration
-import io
+from __future__ import print_function
import os
import re
from xml.etree import ElementTree
self.filename = name
self.element = element
- def __str__(self):
- buf = io.StringIO()
- self.element.write(buf)
- return buf.getvalue()
-
-
# PART IV - Persistence Mapping
# Node class. a non-public class which will represent the DB-persisted
n = _Node()
n.tag = str(node.tag)
n.text = str(node.text)
- n.tail = str(node.tail)
+ n.tail = str(node.tail) if node.tail else None
n.children = [traverse(n2) for n2 in node]
n.attributes = [
_Attribute(str(k), str(v)) for k, v in node.attrib.items()
print("\nFull text of document 'text.xml':", line)
document = session.query(Document).filter_by(filename="test.xml").first()
-print(document)
+ElementTree.dump(document.element)
# PART VI - Searching for Paths
.filter(and_(_Node.tag == "field1", _Node.text == "hi"))
.one()
)
-print(d)
+ElementTree.dump(d.element)
# generalize the above approach into an extremely impoverished xpath function:
# PART I - Imports/Configuration
+from __future__ import print_function
import io
import os
import re
self.filename = name
self.element = element
- def __str__(self):
- buf = io.StringIO()
- self.element.write(buf)
- return buf.getvalue()
-
# PART IV - Persistence Mapping
print("\nFull text of document 'text.xml':", line)
document = session.query(Document).filter_by(filename="test.xml").first()
-print(document)
+ElementTree.dump(document.element)
# PART VI - Searching for Paths
.filter(and_(_Node.tag == "field1", _Node.text == "hi"))
.one()
)
-print(d)
+ElementTree.dump(d.element)
# generalize the above approach into an extremely impoverished xpath function:
from sqlalchemy import Table
from sqlalchemy.orm import mapper
from sqlalchemy.orm import Session
-from sqlalchemy.util import py3k
e = create_engine("sqlite://")
document = session.query(Document).filter_by(filename="test.xml").first()
# print
-if py3k:
- document.element.write(sys.stdout, encoding="unicode")
-else:
- document.element.write(sys.stdout)
+ElementTree.dump(document.element)