[XML-SIG] Working with non-compliant XML utilities

Andrew Clover and-xml at doxdesk.com
Fri Dec 12 04:56:13 EST 2003

Lowell Alleman <lalleman at mfps.com> wrote:

> I need to tell the writer not to do so for certain elements.

(Speaking of which: the empty-text-node trick seems to work with 4DOM too.

> The sad part about all of this really is that the tool that I'm having these
> issues with is a data translation tool

Aye, that's a pretty poor data translation tool.

> The order that the attributes should appear happens to be the same order
> that they are listed in the <!ATTRLIST> in the DTD.  I've tried to pull out
> the DTD info using 4DOM and minidom, but haven't had much success.

No, they don't make this available; as Martin says, you'll need to fiddle
with a processor to get at this info.

Alternatively, in another tiresome plug for my own imp, pxdom goes give one
access to the ATTLIST declararions, and guarantees the declarations will be
in document order. To get a list of attr names, you could say:

  decls= document.doctype.pxdomAttlists.getNamedItem('tagName').declarations
  attrNames= [decl.nodeName for decl in decls]

Or to sort an element's attributes in one go:

  def sortAttributesByAttlistOrder(element):
    doctype= element.ownerDocument.doctype
    if doctype is not None:
      attlist= doctype.pxdomAttlists.getNamedItem(el.tagName)
      if attlist is not None:
        for attdecl in attlists.declarations:
          attr= element.getAttributeNode(attdecl.nodeName)
          if attr is not None:

The drawback is that pxdom doesn't (currently) use external entities,
including the DTD external subset, so you'd have to cram the <!ATTLIST>s
into the internal subset for it to work.

> (I tried the inline DTD when using for minidom.  I assumed that minidom
> wouldn't pick it up automatically, as it is not a validating parser.

Yes, minidom also does not use external entities.

> I did notice that 4DOM seemed to choke on ENTITY references ( %entity_ref; )
> when the DTD was inline.

Hmm. Using expat it (and minidom) seem to ignore parameter entities, but I
can't get it to choke as such. If you are getting an 'Illegal parameter
entity reference', that'll be because XML is stricter about where it allows
parameter entities in the internal subset than in an external DTD.

Andrew Clover
mailto:and at doxdesk.com

More information about the XML-SIG mailing list