#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    29
    Rep Power
    0

    xml append weird behaviour


    Hi Folks,

    hows everyone doing all well i hope

    heres a weird one got me beat

    xml file
    Code:
    <settings>
            <protected>
                    <file>boo.txt</file>
                    <file>who.txt</file>
            </protected>
    </settings>
    Python file
    Code:
    from xml.dom import minidom
    
    def _getProtectedData(tag):
            files = []
            elems = protect.getElementsByTagName(tag)
            if len(elems) > 0 and len(elems[0].childNodes) > 0:
                    for i in range(len(elems)):
                            files.append(elems[i].childNodes[0].data)
                    return files
            return ''
    
    doc = minidom.parse(open('#upstream.xml', 'r'))
    protect = doc.getElementsByTagName('protected')[0]
    
    print _getProtectedData('file')
    The result
    [u'boo.txt', u'who.txt']

    WTF is the *u* in front its got me buggered where thats coming from. I added a print statement inside the loop of the function and it doesnt appear there only seems to happen when append is involved.

    many thanks.

    greets to my buddy netytan love ya bro
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Posts
    89
    Rep Power
    13
    that means your string is a unicode string

IMN logo majestic logo threadwatch logo seochat tools logo