strange DOM behaviour when using minidom

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

    #1

    strange DOM behaviour when using minidom

    Hello, I have a really strange problem. I'm unable to figure it out on
    my own.

    I parse very simple xml documents, without any check for their form.
    These files look very similar and are encoded in UTF-8.

    Now minidom is always able to parse these files with
    minidom.parse(" file") .
    Now when fetching I use this expression:
    xmldoc.getEleme ntsByTagName('D ocNumb')[0].firstChild.dat a.encode('latin 1')

    (I know it's not beautiful but convenient. )

    It always work, but sometimes it simply fails to fetch any element.
    Redoing it from hand in the python console with the same file always
    works.

    I have no idea what the error is. I compared working and not working
    files with the hex editor. I couldn't find any significant change. It's
    too strange. If anybody has any clue, hint or anything, please let me
    know.

    Regards, Jonatan

  • JoReiners

    #2
    Re: strange DOM behaviour when using minidom

    Sorry, I just found the error. Simple an empty attribute. Python showed
    me strange row numbers. I used a multi line initialization of a dict.
    The error always appeared on the first line although I was on an other
    line.

    Interesting behavior.

    Jonatan

    JoReiners schrieb:
    Hello, I have a really strange problem. I'm unable to figure it out on
    my own.
    >
    I parse very simple xml documents, without any check for their form.
    These files look very similar and are encoded in UTF-8.
    >
    Now minidom is always able to parse these files with
    minidom.parse(" file") .
    Now when fetching I use this expression:
    xmldoc.getEleme ntsByTagName('D ocNumb')[0].firstChild.dat a.encode('latin 1')
    >
    (I know it's not beautiful but convenient. )
    >
    It always work, but sometimes it simply fails to fetch any element.
    Redoing it from hand in the python console with the same file always
    works.
    >
    I have no idea what the error is. I compared working and not working
    files with the hex editor. I couldn't find any significant change. It's
    too strange. If anybody has any clue, hint or anything, please let me
    know.
    >
    Regards, Jonatan

    Comment

    Working...