from xml.dom.minidom import parse
dom1=parse('c:/domain.xml')
obj=lambda x:x.localName=='OBJ'
nodelist1=dom1.getElementsByTagName('XPD:OBJ')
entity=''
fname=''
ftype=''
fdesc=''
for node in nodelist1:
if node.getAttribute('type')=='UMLClass':
entity=node.childNodes[1].firstChild.nodeValue
print "Entity name is: %s </p>" % entity
print "<TABLE>"
fields=[x for x in node.childNodes if obj(x)]
for objfield in fields:
for subfield in objfield.childNodes:
if subfield.nodeType==1:
if subfield.getAttribute('name')=="Name":
fname=subfield.firstChild.nodeValue
if subfield.getAttribute('name')=="TypeExpression":
ftype=subfield.firstChild.nodeValue
if subfield.getAttribute('name')=="InitialValue":
fdesc=subfield.firstChild.nodeValue
print """
<TR>
<TD>%s</TD>
<TD>%s</TD>
<TD>%s</TD>
</TR>
"""%(fname,ftype,fdesc)
print "</TABLE>"
Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts
Monday, April 27, 2009
A completely example for how to read xml in Python
Subscribe to:
Posts (Atom)