xml.dom.minidom help!

Discussion in 'Python' started by Paulo Pinto, Jun 9, 2004.

  1. Paulo Pinto

    Paulo Pinto Guest

    Hi,

    I having a problem with xml.dom.minidom parser while
    reading some in-house XML configuration files.

    The files have a DTD at the begining of the file
    specying the XML structure. Some of the attributes
    are declared with a default value in case they are
    not present in the tags.

    When I read the file the parser builds the DOM nodes
    with those default values. So when I write the file
    I get those default values inside the tags!


    For example, the DTD has the following entry

    <!ELEMENT rel (#PCDATA)*>
    <!ATTLIST rel
    name CDATA #REQUIRED
    num CDATA "-1"
    >


    So when if I read the tag

    <rel name="some name"/>

    When I write it back, I get

    <rel name="some name" num="-1"/>


    I don't want this behaviour. Is it possible to change?


    Thanks in advance,
    Paulo Pinto
    Paulo Pinto, Jun 9, 2004
    #1
    1. Advertising

  2. Paulo Pinto <> wrote:

    > When I read the file the parser builds the DOM nodes
    > with those default values. So when I write the file
    > I get those default values inside the tags!


    > I don't want this behaviour. Is it possible to change?


    Not AFAIK, short of deleting the attributes manually. minidom does not
    support Attr.specified. (See:

    http://pyxml.sourceforge.net/topics/compliance.html

    though actually minidom/4DOM are actually broken in a slightly more
    involved way than described here, should update that really.)

    pxdom will do it OK, if the DOM Level 3 LS 'discard-default-content'
    property is set True on LSSerializer.domConfig, which it is by
    default.

    --
    Andrew Clover
    mailto:
    http://www.doxdesk.com/
    Andrew Clover, Jun 10, 2004
    #2
    1. Advertising

  3. Paulo Pinto

    Paulo Pinto Guest

    pxdom doesn't work either.

    It fails to read the DTD declarations inside the files. :(

    I'll have to look for alternative ways of manipulating
    the files.

    Thanks anyway,
    Paulo

    Andrew Clover wrote:
    > Paulo Pinto <> wrote:
    >
    >
    >>When I read the file the parser builds the DOM nodes
    >>with those default values. So when I write the file
    >>I get those default values inside the tags!

    >
    >
    >>I don't want this behaviour. Is it possible to change?

    >
    >
    > Not AFAIK, short of deleting the attributes manually. minidom does not
    > support Attr.specified. (See:
    >
    > http://pyxml.sourceforge.net/topics/compliance.html
    >
    > though actually minidom/4DOM are actually broken in a slightly more
    > involved way than described here, should update that really.)
    >
    > pxdom will do it OK, if the DOM Level 3 LS 'discard-default-content'
    > property is set True on LSSerializer.domConfig, which it is by
    > default.
    >
    Paulo Pinto, Jun 10, 2004
    #3
  4. Paulo Pinto <> wrote:

    > pxdom doesn't work either.


    > It fails to read the DTD declarations inside the files. :(


    It shouldn't fail, if the declarations are in the internal subset, and
    there isn't an external parameter entity reference prior to the
    declaration. (If this isn't the case, minidom shouldn't be able to
    read them either.)

    If you're seeing different I'd definitely be interested to see an
    example problem file.

    --
    Andrew Clover
    mailto:
    http://www.doxdesk.com/
    Andrew Clover, Jun 11, 2004
    #4
  5. Paulo Pinto

    Paulo Pinto Guest

    Hi Andrew,

    I tried to mail you using both email addresses
    that you have on your post, but both failed. :(

    If you still interested in receiving the file that
    gives the parse error, just let me know.

    --
    Paulo Pinto

    Andrew Clover wrote:
    > Paulo Pinto <> wrote:
    >
    >
    >>pxdom doesn't work either.

    >
    >
    >>It fails to read the DTD declarations inside the files. :(

    >
    >
    > It shouldn't fail, if the declarations are in the internal subset, and
    > there isn't an external parameter entity reference prior to the
    > declaration. (If this isn't the case, minidom shouldn't be able to
    > read them either.)
    >
    > If you're seeing different I'd definitely be interested to see an
    > example problem file.
    >
    Paulo Pinto, Jun 16, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roman Yakovenko

    xml.dom.minidom - bug ? future ?

    Roman Yakovenko, Sep 4, 2003, in forum: Python
    Replies:
    1
    Views:
    330
    =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=
    Sep 4, 2003
  2. Greg Wogan-Browne
    Replies:
    1
    Views:
    784
    Uche Ogbuji
    Jan 28, 2005
  3. Replies:
    3
    Views:
    517
    Stefan Behnel
    Aug 3, 2007
  4. Johannes Bauer
    Replies:
    7
    Views:
    1,052
    Johannes Bauer
    Jun 11, 2009
  5. ming
    Replies:
    2
    Views:
    123
Loading...

Share This Page