xml.dom.minidom help!

P

Paulo Pinto

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
 
A

Andrew Clover

Paulo Pinto said:
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.
 
P

Paulo Pinto

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
 
A

Andrew Clover

Paulo Pinto said:
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.
 
P

Paulo Pinto

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top