Documentation for xuproc ================================================ 1. update text nodes >>> from xupdate_processor import applyXUpdate >>> from lxml import etree >>> from cStringIO import StringIO >>> xml_doc_string = """ ... ... ... A ... ... ... A ... ... ... A ... ... ... """ >>> 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) A B C 2. Update Text Node with special chars and entities >>> xml_doc_string = """ ... ... ... description1 --- $sdfrç_sdfsçdf_oisfsopf ... Kamada ... Kamada ... ... ... ... ... ... """ >>> xml_xu_string = """ ... ... description3 çsdf__sdfççç_df___&amp;&amp;é]]]°°°°°° ... 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) description3 çsdf__sdfççç_df___&amp;&amp;é]]]°°°°°° Tatuya Kamada 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 version="1.0"?><marshal><tuple><string>Manager</string><string>Owner</string></tuple></marshal> ... <?xml version="1.0"?> ... <?xml version="1.0"?> ... <?xml version="1.0"?> ... ... ... """ >>> 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) <?xml version="1.0"?><marshal><tuple><string>Owner</string></tuple></marshal> Go to the beach <?xml version="1.0"?> <?xml version="1.0"?> <?xml version="1.0"?> <?xml version="1.0"?> 5. rename element >>> xml_doc_string = """ ... ... ... 313730 ... Tatuya Kamada ... ... ... """ >>> 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) 313730 Tatuya Kamada 6. Update attribute >>> xml_doc_string = """ ... ... ... <?xml version="1.0"?><marshal><tuple><string>Owner</string></tuple></marshal> ... ... ... """ >>> 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) <?xml version="1.0"?><marshal><tuple><string>Owner</string></tuple></marshal> 7. update Two attribue >>> xml_doc_string = """ ... ... ... Data ... ... ... """ >>> 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) Data 8. remove two attribue >>> xml_doc_string = """ ... ... ... Data ... ... ... """ >>> 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) Data 9. inster-before >>> xml_doc_string = """ ... ... ... Data ... ... ... """ >>> 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) Data 10. inster-after >>> xml_doc_string = """ ... ... ... Data ... ... ... """ >>> 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) Data 11. Namespace handling >>> xml_doc_string = """ ... ... ... A ... ... ... A ... ... ... A ... ... ... """ >>> 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) A B A B C 12. Modify Attributes with Qualified Name >>> xml_doc_string = """ ... ... ... A ... ... ... """ >>> 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) A 13. Modify nodes with Qualified Names at root level >>> xml_doc_string = """ ... ... ... A ... ... ... """ >>> 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) A 14. processing-instruction and comments >>> xml_doc_string = """ ... ... ... 313730 ... Tatuya Kamada ... ... ... """ >>> 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) 313730 Tatuya Kamada 15. variables >>> xml_doc_string = """ ... ... ... Tatuya Kamada ... ... ... """ >>> 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) Tatuya Kamada Tatuya Kamada 16. value-of >>> xml_doc_string = """ ... ... ... Tatuya Kamada ... ... ... """ >>> 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) Tatuya Kamada Tatuya Kamada 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) ''