def py_test_02(): # parse content (doc, err) = axl.parse ("<content><load><value test='10' /></load></content>") if err: error ("Expected to find proper parse operation but found an error: " + err.msg) return False # get the node node = doc.get ("/content/load/value") node2 = axl.Node ("test") node2.attr ('id', "10") # do replace node.replace (node2) (content, size) = doc.dump () # check value if content != "<?xml version='1.0' ?><content><load><test id='10' /></load></content>": return False # now swap two nodes (doc, err) = axl.parse ("<content><load><value test='10' /><value2 test='20' /></load></content>") if err: error ("Expected to find proper parse operation but found an error: " + err.msg) return False node = doc.get ("/content/load/value") node2 = doc.get ("/content/load/value2") # disconnect node from document node.deattach () # now place after node2.set_child_after (node) (content, size) = doc.dump () # check value if content != "<?xml version='1.0' ?><content><load><value2 test='20' /><value test='10' /></load></content>": return False return True
def py_test_04_load (): # parse content (doc, err) = axl.parse ("<content><load><value test='10' /></load></content>") if err: error ("Expected to find proper parse operation but found an error: " + err.msg) return False # get the node return doc.get ("/content/load/value")
def test_01(): # do two consecutive parse operations (doc, err) = axl.parse ("<?xml version='1.0' ?><axldoc />", 32) if err: error ("Found error: " + str (err.code) + ", message: " + err.msg) return False (doc, err) = axl.parse ("<?xml version=\"1.0\" \t \n \r encoding='utf-8\" ?> <data />", 63) if err: error ("Found error: " + str (err.code) + ", message: " + err.msg) return False # check doc encoding if doc.encoding != "utf-8": error ("Error, expected to find enconding value utf-8 but found: " + doc.encoding) return False # do a fail parse operation (doc, err) = axl.parse ("aefadsadsf<?xml version=\"1.0\" \t \n \r encoding='utf-8\" ?> <data />", 73) if not err: error ("Expected to find error but found no error report") return False # check error returned if not err.code == -2: error ("Expected to find error code -2 but found: " + str (err.code)) # check standalone configuration (doc, err) = axl.parse ("<?xml version='1.0' encoding='utf-8' standalone='yes' ?> <data/>", 65) if err: error ("Expected to find proper document parse but a failure was found: " + err.msg) return False if not doc.standalone: error ("Expected to find standalone enabled but found it disabled") return False return True
def test_03(): (doc, err) = axl.parse ("<?xml version='1.0' ?>\n\ <complex>\n\ <data>\n\ <row>10</row><row>20</row><row>30</row><row>40</row>\n\ </data>\n\ <data2>\n\ <td> 23 </td>\n\ </data2>\n\ </complex>", -1) if err: error ("Expected to find proper document load, but a failure was found: " + err.msg) return False if doc.root.name != "complex": error ("Expected to find complex node name but found: " + doc.root.name) return False node = doc.get ("/complex/data2/td") if not node: error ("Expected to find node found at /complex/data2/td") return False # check node name if node.name != "td": error ("Expected to find node name td but found: " + node.name) return False node = doc.get ("/complex/data3/td") if node: error ("Expected to not find node in wrong path but found: " + node.name) return False (content, size) = doc.get ("/complex/data2/td").content if content != " 23 ": error ("Expected to find content ' 23 ' but found: " + content) return False node = doc.get ("complex/data3/td") if node: error ("Expected to find no node but found: " + node.name) return False return True
def py_test_01(): # parse content (doc, err) = axl.parse ("<content />") if err: error ("Expected to find proper parse operation but found an error: " + err.msg) return False # get the node node = doc.root # get document containing node doc2 = node.doc if doc2.root.name != "content": error ("Expected to find node name: content but found: " + doc2.root.name) return False return True
def py_test_03(): # parse content (doc, err) = axl.parse ("<content><load><value test='10' /></load></content>") if err: error ("Expected to find proper parse operation but found an error: " + err.msg) return False # get the node node = doc.get ("/content/load/value") info ("Got root node, creating child nodes..") iterator = 0 while iterator < 100: # now add content to the node # info ("About to create child node, iterator=" + str (iterator)) node2 = axl.Node ("test") node.set_child (node2) iterator += 1 return True
def test_04(): (doc, err) = axl.parse ("<?xml version='1.0' ?>" + " <?test \"my content\" ?>" + " <complex>" + " <data>" + " <row>" + " <!-- A comment inside the middle of the document " + " more comments ... " + " more comments \n \r <td>..</td> -->" + " <td>10</td>" + " <test />" + " \n \n \r <?test \"my content\" ?> \n \n" + " <?test \"my content\" ?>" + " <more>" + " <test3 attr='2.0' />" + " </more>" + " </row>" + " <test2 />" + " <non-xml-document>" + " \n \r \n \t" + " <![CDATA[<xml><<<<<<>>>>>><<<>>>><<<<<<>>>]]>" " \r \n \r \t" + " </non-xml-document>" + " </data>" + " <!-- <data>" + " <row>" + " A comment inside the middle of the document " + " more comments ... " + " more comments \n \r <td>..</td> " + " <td>10</td>" + " <test />" + " <more>" + " <test2 attr='2.0' attr2='3.0' attr4='4.0'/>" + " </more>" + " </row>" + " <test2 />" + " </data> -->" + " </complex>", -1) if err: error ("Expected to find proper parse result but found a failure: " + err.msg) return False if doc.get ("/complex/data/row/td").content[0] != "10": error ("Expected to find content 10 but found: " + doc.get ("/complex/data/row/td").content[0]) return False node = doc.get ("/complex/data/row/more/test3") if not node.has_attr ("attr"): error ("Expected to find attribute attr but not found") return False # now check attr content if node.attr ("attr") != "2.0": error ("Expected to find attribute value 2.0 but found: " + node.attr ("attr")) return False # check pi instructions support if not doc.has_pi ("test"): error ("Expected to find pi instruction test but not found") return False if doc.pi ("test") != "\"my content\"": error ("Expected to find 'my content' but found: " + doc.pi ("test")) return False # check node content if doc.get ("/complex/data/non-xml-document").content[0] != "<xml><<<<<<>>>>>><<<>>>><<<<<<>>>": error ("Expected to find <xml><<<<<<>>>>>><<<>>>><<<<<<>>> but found: " + doc.get ("/complex/data/non-xml-document").content[0]) return False return True