[Python-au] xml.dom.minidom
Andy Dent
dent@oofile.com.au
Sat, 18 Jan 2003 22:38:42 +0800
I believe this is more like what you're after (yes, it works).
kSample = """<Order>
<OrderId>12345</OrderId>
<Date>12/03/2002</Date>
</Order>
"""
from xml.dom.minidom import parseString
#import Order
#import OrderLine
class OrderMessageProcessor(object):
def __init__ (self,data=None):
#self.order = Order.Order()
self.data = data
def processOrder(self):
xmlTree = parseString(self.data)
assert xmlTree.documentElement.tagName == 'Order'
order = xmlTree.getElementsByTagName('Order')[0]
orderID = order.getElementsByTagName('OrderId')[0]
# we are now concerned with the contents of the element,
# which are parsed as child nodes of class Node
# the nodeName is #text as this is pure text content
orderIDValue = orderID.firstChild.nodeValue
print orderIDValue
xmlTree.unlink()
def testDOM():
omp = OrderMessageProcessor(kSample)
omp.processOrder()
if __name__ == '__main__':
testDOM()
--
Andy Dent BSc MACS AACM http://www.oofile.com.au/
OOFILE - Database, Reports, Graphs, GUI for c++ on Mac, Unix & Windows
PP2MFC - PowerPlant->MFC portability