"""This File is to be used as a example of some simple uses of the Pyxie2 module""" __author__ = "Derek Higgins" import Pyxie2.Pyxie2Utils import Pyxie2.Pyxie2TP if __name__ == "__main__": # In this program I will print out the name and phone numbers of all # the people in example.xml using 2 methodes # First we need to build out xTree xTree = Pyxie2.Pyxie2Utils.File2xTree("example.xml") # Don't worry about this yet xTree = Pyxie2.Pyxie2TP.NoMixedContentTP(xTree) # The First Method is using our Up, Down and Left methods print "\n 1. ------------------------------------\n" xTree.Down() while(1): print " Name = %s"%xTree.Cursor.AVs.get("Name", "") #Now we go down and find the Phone Number xTree.Down() while(1): if xTree.Cursor.ETN == "TelNo": xTree.Down() print " Tel No. = %s"%xTree.Cursor.Data xTree.Up() if xTree.HasRight(): xTree.Right() else: break xTree.Up() if xTree.HasRight(): xTree.Right() else: break xTree.Home() # The Secound method make use of xTree's Children member function, Better print "\n 2. ------------------------------------\n" for x in xTree.Children(): xTree.Seek(x) # Set Cursor Node to x print " Name = %s"%xTree.Cursor.AVs.get("Name", "") for y in xTree.Children(): xTree.Seek(y) # Set Cursor Node to x if xTree.Cursor.ETN == "TelNo": xTree.Down() print " Tel No. = %s"%xTree.Cursor.Data xTree.Up()