You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Frank Taffelt <fr...@interface-business.de> on 2000/06/23 13:11:10 UTC

GrammarAccess as Tree

adding the grammar to an Document, fails

here is a part of my code:
----------
document = parser.getDocument(); 
doctype =  document.getDoctype(); /* the grammar */

/* building a new document with this grammar as content tree */
Document doc= new DocumentImpl();
Element root = doc.createElement("root");
doc.appendChild(root);
root.appendChild(doctype); /* 
//root.importNode(doctype,true);
OutputFormat    format  = new OutputFormat( doc );
//Serialize the DOM
format.setIndenting(true);
format.setLineSeparator("\n");
StringWriter  stringOut = new StringWriter();
XMLSerializer    serial = new XMLSerializer( stringOut, format );
serial.asDOMSerializer();
serial.serialize( doc.getDocumentElement() );
System.out.println(stringOut.toString());
----------------------
the exception :
Exception in thread "main" org.apache.xerces.dom.DOMExceptionImpl: DOM006
Hierarchy request error

can anybody explain this ?


regards
frank






Re: GrammarAccess as Tree

Posted by Andy Clark <an...@apache.org>.
Frank Taffelt wrote:
> doctype =  document.getDoctype(); /* the grammar */
> [...]
> Element root = doc.createElement("root");
> [...]
> root.appendChild(doctype); /*

The only DOM node that is allowed to have a DocumentType node
as a child is the Document node. Check the spec for details.

BTW, the doctype is not representative of the document's
grammar. At least not yet. Perhaps in DOM Level 3 there will
be an adequate description of the grammar.

-- 
Andy Clark * IBM, JTC - Silicon Valley * andyc@apache.org