Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > xml.dom.minidom help!

Reply
Thread Tools

xml.dom.minidom help!

 
 
Paulo Pinto
Guest
Posts: n/a
 
      06-09-2004
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
 
Reply With Quote
 
 
 
 
Andrew Clover
Guest
Posts: n/a
 
      06-10-2004
Paulo Pinto <(E-Mail Removed)> 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
(E-Mail Removed)
http://www.doxdesk.com/
 
Reply With Quote
 
 
 
 
Paulo Pinto
Guest
Posts: n/a
 
      06-10-2004
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 <(E-Mail Removed)> 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.
>

 
Reply With Quote
 
Andrew Clover
Guest
Posts: n/a
 
      06-11-2004
Paulo Pinto <(E-Mail Removed)> 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
(E-Mail Removed)
http://www.doxdesk.com/
 
Reply With Quote
 
Paulo Pinto
Guest
Posts: n/a
 
      06-16-2004
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 <(E-Mail Removed)> 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.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments