from xml.dom.minidom import parse
import xml.dom.minidom
from xml.dom.minidom import Node
def read_xml(filename, record_root):
doc = xml.dom.minidom.parse(filename)
recordRootNode = doc.getElementsByTagName(record_root)[0]
fields = read_xml_record(recordRootNode).keys()
records = [fields]
for node in recordRootNode.childNodes:
record_dict = read_xml_record(node)
record_list = []
for field in fields:
if record_dict.has_key(field):
record_list.append(record_dict[field])
else:
record_list.append(None)
records.append(record_list)
return records
def read_xml_record(record_node):
record = {}
choices =[e for e in record_node.childNodes if e.nodeType==e.ELEMENT_NODE]
#print choices
if ((not (node.nodeType == Node.TEXT_NODE)) and (not (node.nodeType == Node.CDATA_SECTION_NODE))):
for node in choices:
record[node.data] = node.childNodes[0].data
return record
myDoc=read_xml("page1.xml",'page')
need HELP!!!
ps: this is the sample xml file
<page>
<title>Darsheel Safary</title>
<id>15276803</id>
<revision>
<id>236885217</id>
<timestamp>2008-09-07T16:24:50Z</timestamp>
<contributor>
<username>Shshshsh</username>
<id>2789676</id>
</contributor>
<minor/>
<comment>Reverted edits by [[Special:Contributions/Karunsheel05|Karunsheel05]] ([[User talk:Karunsheel05|talk]]) to last version by BOLLYWOOD DREAMZ</comment>
<text xml:space="preserve">{{Infobox actor
| name = Darsheel Safary
| image = DarsheelSafary.jpg
| imagesize =
| caption = Darsheel Safary on [[Sa Re Ga Ma Pa L'il Champs International]] (2007).
| birthname =
| birthdate = {{birth date and age|1996|3|9}}
| location = [[India]]
| occupation = [[Film actor]]
| yearsactive = 2007-present
| spouse =
| homepage =
}}
'''Darsheel Safary''' (born March 9, 1996) is an award winning [[India]]n film actor working in [[Hindi]] [[Bollywood]] films. He is best known for his highly critically acclaimed portrayal of a [[dyslexic]] child in the 2007 film ''[[Taare Zameen Par]]''.<ref name="NFA">{{cite web|title="Darsheel deserves National Award for
[[Category:Indian child actors]]
[[Category:Living people]]</text>
</revision>
</page>

New Topic/Question
Reply




MultiQuote


|