Re: XML version number via DOM

On Wed, Mar 21, 2001 at 07:16:07PM -0800, Dylan Schiemann wrote:
> --- Jeff Yates <pbwiz@pbwizard.com> wrote:
> > At the beginning of every XML document there is a
> > <?xml version="1.0" ?>
> > tag.  Is there a way to get this version number from
> > within DOM?  I know at
> > this time there is only one version number, but in
> > the future there may be
> > more.
> 
> I would think that it would be an attribute of that
> node. So
> document.childNodes[index].getAttribute("version")
> would do the trick, assuming a correct implementation.

A correct implementation does not model the <?xml version="1.0"?> tag; it
is not a Processing Instruction (even though some DOM implementations have
modelled the XML declaration as a PI Node). Besides, a PI doesn't have
attributes.

This isn't available in DOM level 2 at all. DOM level 3 does give access
to the information given in the XML declaration through attributes of the
Document Interface:

  Document.version
  Document.encoding
  Document.standalone

-- 
Martijn Pieters
| Software Engineer  mailto:mj@digicool.com
| Digital Creations  http://www.digicool.com/
| Creators of Zope   http://www.zope.org/
---------------------------------------------

Received on Thursday, 22 March 2001 03:19:30 UTC