Wiki
Clone wikidata2l / help-api
API Interfaces Description
Python DOM interfaces
Common methods for Void, Basic, Struct, Array, Alternative
-
Init() - Initializes and loads a structure. Init is caller recurrently for all sub-elements.
-
getValue() - returns the value of specific element.
Array methods
-
loadIndex(idx) - Loads structure at specified index structure. loadIndex changes the "state" of DOM instance.
-
getElementAt(idx) - if has a in_memory set. Returns tuple of array substructures on a specified index.
Example of python DOM access
import DOM
import Reader
import Writer
import Definition
compiled_def = Definition.load_and_compile("../file_defs/AddressBook.py")
# Create empty DOM structure of the address book file format.
addressBook = DOM.DOMStruct( Reader.ReaderA("addressbook.dat"), compiled_def.dep_root , None)
addressBook.Init()
# dot notation reflects the tree structure of AddressBook Definition
print addressBook.AddressArray.AddrRec.Name.getValue()
addressBook.AddressArray.loadIndex(1) #DOM state is changed
print addressBook.AddressArray.AddrRec.Name.getValue()
Python SAX
Example of python SAX access
\ import DOM import SAX import Reader import Writer import Definition
class SaxCallback(SAX.SAXHandler):
def beginElement(self, dom_element):
print "beginElement " + str(dom_element)
def endElement(self, dom_element):
print "endElement " + str(dom_element) + " " + str(dom_element.getValue())
compiled_def = Definition.load_and_compile("../file_defs/AddressBook.py")
addressBook = DOM.DOMStruct( Reader.ReaderA("addressbook.dat"), compiled_def.dep_root , None)
addressBook.Init()
parser = SAX.SAXParser(addressBook, skip_simple = True)
parser.parse(SaxCallback())
Updated