xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Hodges <harmo...@swbell.net>
Subject Re: Another question about using Xerces
Date Wed, 01 Mar 2000 19:32:01 GMT
I stepped into the source before I posted here.  This is the source, from
org.apache.xerces.dom.DocumentImpl:

    /**
     * Since a Document may contain at most one top-level Element child,
    * and at most one DocumentType declaraction, we need to subclass our
    * add-children methods to implement this constraint.
  * Since appendChild() is implemented as insertBefore(,null),
  * altering the latter fixes both.
    * <p>
    * While I'm doing so, I've taken advantage of the opportunity to
    * cache documentElement and docType so we don't have to
    * search for them.
  */
    public Node insertBefore(Node newChild, Node refChild)
        throws DOMException {

     // Only one such child permitted
        int type = newChild.getNodeType();
        if (errorChecking) {
            if((type == Node.ELEMENT_NODE && docElement != null) ||
               (type == Node.DOCUMENT_TYPE_NODE && docType != null)) {
                throw new
DOMExceptionImpl(DOMException.HIERARCHY_REQUEST_ERR,
                                           "HIERARCHY_REQUEST_ERR");
            }
        }

I'm not on the Xerces list, and this code didn't make any sense to me.  I
have no idea what docElement is and why it needs to be null.


----- Original Message -----
From: Mike Pogue <mpogue@apache.org>
To: <general@xml.apache.org>
Sent: Wednesday, March 01, 2000 11:21 AM
Subject: Re: Another question about using Xerces


> Eric,
>
> You should post this to the Xerces list.  But, here's the quick answer:
> HIERARCHY_REQUEST_ERR is documented in the XML specification, at:
>
> http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html
>
> If you debug into the source code, where the exception is thrown, it will
probably
> give you a lot of info about where the problem is.
>
> Mike
>
> > Eric Hodges wrote:
> >
> > I'm trying to build a document using Xerces.  Here's some simple code
that demonstrates my
> > problem:
> >
> >   public XercesTest() {
> >     DOMImplementationImpl imp = new DOMImplementationImpl();
> >     Document doc = imp.createDocument(null, "Test", null);
> >     Element e = doc.createElement("dummElement");
> >     doc.appendChild(e);
> >   }
> >
> > Here's the error I receive:
> > org.apache.xerces.dom.DOMExceptionImpl: HIERARCHY_REQUEST_ERR
> >  at org.apache.xerces.dom.DocumentImpl.insertBefore(Compiled Code)
> >  at org.apache.xerces.dom.NodeImpl.appendChild(Compiled Code)
> >  at XercesTest.XercesTest.<init>(XercesTest.java:19)
> >  at XercesTest.XercesTest.main(XercesTest.java:23)
> > What's a HIERARCHY_REQUEST_ERR and where is it documented?
> > What's the correct way to add a new element to a document?
> >
> > Thanks.
> >


Mime
View raw message