XML dom question

G

George

How can I do the following in python:

compare the text in the element tags <li> with the elements
tags in filling and if they match replace the text within the elements
tags <li> with the text in the matching element tag of fillin.
For example Since the text Monday in form matches the Element tag
<Monday> in fillin put maandag in the element tag <li> of Monday.


Kind of a Pseudo Code

Fo information:
get element tags for li
get text for li


Fi information:
get childtags for dutchdays


if(text for li=child tags for dutchdays):
replace child tags for dutchdays text with text for li

Some pieces of code that I tried out but cannot put together to get the
results.

import xml.dom.minidom
from xml.dom.minidom import parseString
import xml.xpath

form="""
<html>
<head> <title> My Sample Web Page </title> </head>
<body bgcolor="white">
<p>
What are the weekdays?
<ol>
<li>Monday</li>
<li>Tuesday</li>
<li>Wednesday</li>
<li>Thursday</li>
<li>Friday</li>
</ol>
</p>
</body>
</html>
"""
fillin="""
<dutchdays>
<Monday>maandag</Monday>
<Tuesday>dinsdag</Tuesday>
<Wednesday>woensdag</Wednesday>
<Thursday>donderdag</Thursday>
<Friday>vrijdag</Friday>
<Saturday>zaterdag</Saturday>
<Sunday>zondag</Sunday>
</dutchdays>
"""


fo=xml.dom.minidom.parseString(form)
fi=xml.dom.minidom.parseString(fillin)

mon=fi.getElementsByTagName('Monday')
monlist=mon[0]
m=monlist.childNodes[0]
mo=m.data
fri=fi.getElementsByTagName('Friday')
frilist=fri[0]
f=frilist.childNodes[0]
fr=f.data

for li in xml.xpath.Evaluate("//li", form_doc):
li.normalize()
day_text = li.childNodes[0]
day_str = day_text.nodeValue


Thanks for the help!!
 
G

George Sakkis

George said:
How can I do the following in python:

[snipped]

In exactly the same way you could do it if you actually read the replies to the thread with the same
topic you posted yesterday. Duh!

George
 
G

George

Yes but I cannot get the if statement to work to compare the two or the
replaceChild portion to work. Could someone help me with that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top