Documentation for xuproc
================================================
1. update text nodes
>>> from xupdate_processor import applyXUpdate
>>> from lxml import etree
>>> from cStringIO import StringIO
>>> xml_doc_string = """
...
...
...
...
...
... """
>>> xml_xu_string = """
...
... B
... C
...
... """
>>> result_tree = applyXUpdate(xml_xu_string=xml_xu_string, xml_doc_string=xml_doc_string)
>>> print etree.tostring(result_tree, pretty_print=1)
2. Update Text Node with special chars and entities
>>> xml_doc_string = """
...
...
...
... """
>>> xml_xu_string = """
...
... description3 çsdf__sdfççç_df___&&é]]]°°°°°°
... Tatuya
... 2009/08/28 19:12:24.703 GMT+9
... """
>>> result_tree = applyXUpdate(xml_xu_string=xml_xu_string, xml_doc_string=xml_doc_string)
>>> print etree.tostring(result_tree, pretty_print=1)
3. update two date element which have same id
>>> xml_doc_string = """
...
...
...
... """
>>> xml_xu_string = """
...
... 2009/08/28 19:12:40.905 GMT+9
... 2009/08/28 19:12:40.910 GMT+9
...
... """
>>> result_tree = applyXUpdate(xml_xu_string=xml_xu_string, xml_doc_string=xml_doc_string)
>>> print etree.tostring(result_tree, pretty_print=1)
4. insert and remove elements
>>> xml_doc_string = """
...
...
...
... """
>>> xml_xu_string = """
...
...
...
... tokenstatuya<?xml version="1.0"?><marshal><tuple><string>Owner</string></tuple></marshal>
... Go to the beach
...
...
... tokensManage portal content<?xml version="1.0"?>
...
...
... """
>>> result_tree = applyXUpdate(xml_xu_string=xml_xu_string, xml_doc_string=xml_doc_string)
>>> print etree.tostring(result_tree, pretty_print=1)
5. rename element
>>> xml_doc_string = """
...
...
...
... """
>>> xml_xu_string = """
...
... erp6
...
... """
>>> result_tree = applyXUpdate(xml_xu_string=xml_xu_string, xml_doc_string=xml_doc_string)
>>> print etree.tostring(result_tree, pretty_print=1)
6. Update attribute
>>> xml_doc_string = """
...
...
...
... """
>>> xml_xu_string = """
...
... ccc
...
... """
>>> result_tree = applyXUpdate(xml_xu_string=xml_xu_string, xml_doc_string=xml_doc_string)
>>> print etree.tostring(result_tree, pretty_print=1)
7. update Two attribue
>>> xml_doc_string = """
...
...
...
... """
>>> xml_xu_string = """
...
... ccc
... ccc
...
... """
>>> result_tree = applyXUpdate(xml_xu_string=xml_xu_string, xml_doc_string=xml_doc_string)
>>> print etree.tostring(result_tree, pretty_print=1)
8. remove two attribue
>>> xml_doc_string = """
...
...
...
... """
>>> xml_xu_string = """
...
...
...
...
... """
>>> result_tree = applyXUpdate(xml_xu_string=xml_xu_string, xml_doc_string=xml_doc_string)
>>> print etree.tostring(result_tree, pretty_print=1)
9. inster-before
>>> xml_doc_string = """
...
...
...
... """
>>> xml_xu_string = """
...
...
...
...
...
...
...
... """
>>> result_tree = applyXUpdate(xml_xu_string=xml_xu_string, xml_doc_string=xml_doc_string)
>>> print etree.tostring(result_tree, pretty_print=1)
10. inster-after
>>> xml_doc_string = """
...
...
...
... """
>>> xml_xu_string = """
...
...
...
...
...
...
...
... """
>>> result_tree = applyXUpdate(xml_xu_string=xml_xu_string, xml_doc_string=xml_doc_string)
>>> print etree.tostring(result_tree, pretty_print=1)
11. Namespace handling
>>> xml_doc_string = """
...
...
...
...
...
... """
>>> xml_xu_string = """
...
...
...
... anyvalueB
...
...
...
... A
...
...
...
... Test
... B
...
...
... Test
... C
...
...
...
... """
>>> result_tree = applyXUpdate(xml_xu_string=xml_xu_string, xml_doc_string=xml_doc_string)
>>> print etree.tostring(result_tree, pretty_print=1)
B
12. Modify Attributes with Qualified Name
>>> xml_doc_string = """
...
...
...
... """
>>> xml_xu_string = """
...
... B
...
... """
>>> result_tree = applyXUpdate(xml_xu_string=xml_xu_string, xml_doc_string=xml_doc_string)
>>> print etree.tostring(result_tree, pretty_print=1)
13. Modify nodes with Qualified Names at root level
>>> xml_doc_string = """
...
...
...
... """
>>> xml_xu_string = """
...
... aaa:erp5
...
... B
...
... """
>>> result_tree = applyXUpdate(xml_xu_string=xml_xu_string, xml_doc_string=xml_doc_string)
>>> print etree.tostring(result_tree, pretty_print=1)
14. processing-instruction and comments
>>> xml_doc_string = """
...
...
...
... """
>>> xml_xu_string = """
...
...
... type="aaa"
... This text is a comment
...
...
... """
>>> result_tree = applyXUpdate(xml_xu_string=xml_xu_string, xml_doc_string=xml_doc_string)
>>> print etree.tostring(result_tree, pretty_print=1)
15. variables
>>> xml_doc_string = """
...
...
...
... """
>>> xml_xu_string = """
...
...
...
...
...
...
... """
>>> result_tree = applyXUpdate(xml_xu_string=xml_xu_string, xml_doc_string=xml_doc_string)
>>> print etree.tostring(result_tree, pretty_print=1)
16. value-of
>>> xml_doc_string = """
...
...
...
... """
>>> xml_xu_string = """
...
...
...
...
...
... """
>>> result_tree = applyXUpdate(xml_xu_string=xml_xu_string, xml_doc_string=xml_doc_string)
>>> print etree.tostring(result_tree, pretty_print=1)
17. OOo files 1
>>> orig_filename = 'test_ooo_1.xml'
>>> xu_filename = 'xu_ooo_1.xml'
>>> destination_filename = 'dest_ooo_1.xml'
>>> result_tree = applyXUpdate(xml_xu_filename=xu_filename, xml_doc_filename=orig_filename)
>>> destination_tree = etree.parse(destination_filename)
>>> destination_buffer = StringIO()
>>> result_buffer = StringIO()
>>> destination_tree.write_c14n(destination_buffer)
>>> result_tree.write_c14n(result_buffer)
>>> from ERP5Diff import ERP5Diff
>>> erp5diff = ERP5Diff()
>>> erp5diff.compare(result_buffer.getvalue(), destination_buffer.getvalue())
>>> etree.tostring(erp5diff._result)
''
17. OOo files 2
>>> orig_filename = 'test_ooo_2.xml'
>>> xu_filename = 'xu_ooo_2.xml'
>>> destination_filename = 'dest_ooo_2.xml'
>>> result_tree = applyXUpdate(xml_xu_filename=xu_filename, xml_doc_filename=orig_filename)
>>> destination_tree = etree.parse(destination_filename)
>>> destination_buffer = StringIO()
>>> result_buffer = StringIO()
>>> destination_tree.write_c14n(destination_buffer)
>>> result_tree.write_c14n(result_buffer)
>>> from ERP5Diff import ERP5Diff
>>> erp5diff = ERP5Diff()
>>> erp5diff.compare(result_buffer.getvalue(), destination_buffer.getvalue())
>>> etree.tostring(erp5diff._result)
''