Please Help with replaceChild

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • George

    #1

    Please Help with replaceChild

    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>
    </ol>
    </p>
    </body>
    </html>
    """

    fillin="""
    <dutchdays>
    <Monday>maandag </Monday>
    <Tuesday>dinsda g</Tuesday>
    <Wednesday>woen sdag</Wednesday>
    <Thursday>donde rdag</Thursday>
    <Friday>vrijdag </Friday>
    <Saturday>zater dag</Saturday>
    <Sunday>zonda g</Sunday>
    </dutchdays>
    """

    Fo = xml.dom.minidom .parseString(fo rm)
    Fi = xml.dom.minidom .parseString(fi llin)

    form_doc = parseString(for m)
    fill_doc = parseString(fil lin)

    for li in xml.xpath.Evalu ate("//li", form_doc):
    li.normalize()
    day_text = li.childNodes[0]
    day_str = day_text.nodeVa lue
    for Monday in xml.xpath.Evalu ate("//Monday", fill_doc):
    Monday.normaliz e()
    mon_text = Monday.childNod es[0]
    mon_str = mon_text.nodeVa lue
    #I want the to put the replace here put I have tried everything and
    errors keep coming up

    I am totally lost and do not know what to do could someone explain to
    me what to do because I have looked at the python.org material and have
    accomplished nothing.

    Thanks

Working...