def test_05(): (doc, err) = axl.file_parse ("test.xml") if doc.get ("/complex/data/row/td").content[0] != "10": error ("Expected to find 10 but found: " + doc.get ("/complex/data/row/td").content[0]) return False (doc, err) = axl.file_parse ("test2.xml") if err: error ("Expected to find proper document parsing, but error was found: " + err.msg) return False (dtd, err) = axl.dtd_file_parse ("test.dtd") if err: error ("Expected to find proper dtd parsing, but error was found: " + err.msg) return False # validate content err = dtd.validate (doc) if err: error ("Expected to find proper DTD validation, but a failure was found: " + err.msg) return False return True
def test_01f(): # parse document (doc, err) = axl.file_parse ("test_01f.xml") if err: error ("Expected proper document parse but found a failure: " + err.msg) return False # get root content (content, size) = doc.root.content # check content if content != " ": error ("Expected to find ' ' but found: " + content) return False # parse another document (doc, err) = axl.file_parse ("test_01f2.xml") if err: error ("Expected proper document parse but found a failure: " + err.msg) return False # get content from node id found as child of the root node (content, size) = doc.root.child_called ("id").content # check content if content != " ": error ("(2) Expected to find ' ' but found: " + content) return False (content, size) = doc.root.child_called ("id2").content # check content if content != "": error ("Expected to find '' but found: " + content) return False return True
def test_01b(): # parse document (doc, err) = axl.file_parse ("test_01b.xml") if err: error ("Found error: " + str (err.code) + ", message: " + err.msg) return False info ("Test 01-b: finished document parsing, getting root node") # get root node node = doc.root info ("Test 01-b: checking node name..") # check node name if node.name != "document": error ("Expected to find node name 'document' but found: " + node.name) return False info ("Test 01-b: about to get first reference..") # get first child node = node.first_child info ("Test 01-b: returning..") # check node name if node.name != "child1": error ("Expected to find node name 'child1' but found: " + node.name) return False # get next node = node.next # check node name if node.name != "child2": error ("Expected to find node name 'child2' but found: " + node.name) return False return True
def test_01c(): # parse document (doc, err) = axl.file_parse ("test_01b.xml") if err: error ("Found error: " + str (err.code) + ", message: " + err.msg) return False # get root node node = doc.root # check node name if node.name != "document": error ("Expected to find node name 'document' but found: " + node.name) return False # get first child node = node.first_child # check node name if node.name != "child1": error ("Expected to find node name 'child1' but found: " + node.name) return False # get parent parent = node.parent # check node name if parent.name != "document": error ("Expected to find node name 'document' but found: " + parent.name) return False node = node.next # check node name if node.name != "child2": error ("Expected to find node name 'child2' but found: " + node.name) return False # check parent again parent = node.parent # check node name if parent.name != "document": error ("Expected to find node name 'document' but found: " + parent.name) return False node = node.next # check node name if node.name != "child3": error ("Expected to find node name 'child3' but found: " + node.name) return False # check parent again parent = node.parent # check node name if parent.name != "document": error ("Expected to find node name 'document' but found: " + parent.name) return False node = node.next # check node name if node.name != "child4": error ("Expected to find node name 'child4' but found: " + node.name) return False # check parent again parent = node.parent # check node name if parent.name != "document": error ("Expected to find node name 'document' but found: " + parent.name) return False node = node.next # check node name if node.name != "child5": error ("Expected to find node name 'child5' but found: " + node.name) return False # check next is none if node.next: error ("Expected to find none value for the next child node found next to child5") return False node = node.previous # check node name if node.name != "child4": error ("Expected to find node name 'child4' but found: " + node.name) return False # check node name if parent.name != "document": error ("Expected to find node name 'document' but found: " + parent.name) return False node = node.previous # check node name if node.name != "child3": error ("Expected to find node name 'child3' but found: " + node.name) return False # check node name if parent.name != "document": error ("Expected to find node name 'document' but found: " + parent.name) return False node = node.previous # check node name if node.name != "child2": error ("Expected to find node name 'child2' but found: " + node.name) return False # check node name if parent.name != "document": error ("Expected to find node name 'document' but found: " + parent.name) return False node = node.previous # check node name if node.name != "child1": error ("Expected to find node name 'child1' but found: " + node.name) return False # check node name if parent.name != "document": error ("Expected to find node name 'document' but found: " + parent.name) return False # check previous is none if node.previous: error ("Expected to find none value for the previous child node found previous to child1") return False # now test called api node = doc.root.first_child # get <child5> node = node.next_called ("child5") if node.name != "child5": error ("Expected to find child node with name child5 but found: " + node.name) return False # get <child5> node = node.next_called ("child5") if node: error ("Expected to find none node after calling next_called with child5 but found: " + node.name) return False node = doc.root.first_child.next_called ("child5") if not node: error ("Expected to find a xml node but found none") return False if node.name != "child5": error ("Expected to find child node child5 but found: " + node.name) return False # get <child1> node = node.previous_called ("child1") if not node: error ("Expected to find a xml node child1 but found none") return False if node.name != "child1": error ("Expected to find child node child1 but found: " + node.name) return False node = node.previous_called ("child1") if node: error ("Expected to not find a xml node but found somethind defined: " + node.name) return False return True
def test_01d(): (doc, err) = axl.file_parse ("test_01d.xml") if err: error ("Expected to find proper parse operation but found an error: " + err.msg) return False child = doc.root.nth_child (0) if child.name != "child1": error ("Expected to find child1 node but found: " + child.name) return False child = doc.root.nth_child (1) if child.name != "child2": error ("Expected to find child2 node but found: " + child.name) return False child = doc.root.nth_child (2) if child.name != "child3": error ("(2) Expected to find child3 node but found: " + child.name) return False child = doc.root.nth_child (3) if child.name != "child4": error ("Expected to find child4 node but found: " + child.name) return False child = doc.root.nth_child (4) if child.name != "child5": error ("Expected to find child5 node but found: " + child.name) return False # get the child 0 located at the child 2 child = doc.root.nth_child (2).nth_child (0) if child.name != "a": error ("Expected to find node name <a> but found: " + child.name) return False child = doc.root.nth_child (2).nth_child (1) if child.name != "b": error ("Expected to find node name <b> but found: " + child.name) return False child = doc.root.nth_child (2).nth_child (2) if child.name != "c": error ("Expected to find node name <c> but found: " + child.name) return False child = doc.root.nth_child (2).nth_child (3) if child.name != "f": error ("Expected to find node name <f> but found: " + child.name) return False child = doc.root.nth_child (2).nth_child (4) if child.name != "g": error ("Expected to find node name <g> but found: " + child.name) return False return True