Please help required urgently - xml.dom.minidom

Peter Abel p-abel at t-online.de
Sat Jan 18 17:13:21 EST 2003


"Graeme" <graeme_matthew at hotmail.com> wrote in message news:<JRbW9.196$1y6.12206 at nnrp1.ozemail.com.au>...
> Hi all
> 
> I am at the point of exploding, I have been trying to get my head around
> xml.dom.minidom
> 
> I just cannot seem to get the value for the element/node
> 
> My XML is very simple
> 
> <Order><OrderId>12345</OrderId><Delivery>Definetly Not Microsoft
> Way</Delivery><Order>

----should be   </Order>

> 
> When I pass this to my class instance and process it the output is
> 
> OrderId
> None
> 1
> Delivery
> None
> 1
> 1
> 
> please could someone explain this, many thanks
> 
> Here is my class
> 
> import xml.dom.minidom
> import Order
> import OrderLine
> 
> class OrderMessageProcessor(object):
> 
>     def __init__ (self,data=None):
> 
>         self.order = Order.Order()
>         self.data = data
> 
>     def processOrder(self):
> 
>         xmlTree = xml.dom.minidom.parseString(self.data)
> 
>         #Get a NodeList Object
>         orders = xmlTree.getElementsByTagName('Order')
> 
>         if orders.length != 0:
> 
>             #Loop nod
>             for nod in orders:
> 
>                 for elem in nod.childNodes:
> 
> 
>                     print elem.tagName
Not every Node has a tagName, since it can be a TEXT_NODE or something else
>                     print elem.nodeValue
Every Node should be testet for its type, and depending on its
type you have to do a little bit more to get its value, e.g. if its
a TEXT_NODE you get have to get all its .items and concatenate them
to get the whole string.
>                     print elem.nodeType
> 
> 
>         xmlTree.unlink()

Documentation of xml.dom.minidom is - as it says - <mini>.
You'd better referr to xml.dom's docu.

Regards
Peter




More information about the Python-list mailing list