xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sean Kelly" <ke...@ad1440.net>
Subject Re: Why is "#document" an illegal name?
Date Wed, 18 Oct 2000 23:03:56 GMT
> I'm trying to create a document using
> DOMImplementation.createDocument(namespaceURI, qualifiedName, docType).  I
> get a "DOM002 illegal character" exception because the name I pass in is
> "#document", which is the name DocumentImpl assigned the Document I'm
> to recreate.

You're passing "#document" as the qualifiedName parameter?  The # sign is
illegal in an element name there.

Pass in the name you want to give to the root element instead.  For example,
suppose BoxCo (Silicon Valley's #1 Supplier of Brown 6-Sided Boxes, On The
Web at BoxCo.com, or call 1-800-BOX-CO) created box.dtd, containing a simple
DTD for describing boxes:

<!ELEMENT box (numSides, color)>
<!ELEMENT numSides (#PCDATA)>
<!ELEMENT color (#PCDATA)>

And you want to create a document that on paper looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE box "-//BoxCo//DTD Box 1.0//EN" "http://boxco.com/box.dtd">

You'd create your document type

DocumentType type = impl.createDocumentType("box",
    "-//BoxCo//DTD Box 1.0//EN", http://boxco.com/box.dtd);

and create your document:

Document boxDoc = impl.createDocument(null, "box", type);

And get the <box> element:

Element box = boxDoc.getDocumentElement();

And add nodes to it:

Element numSides = boxDoc.createElement("numSides");
Element color = boxDoc.createElement("color");

And there you have it.  (I probably made a mistake after too many glasses of
wine at lunch though, so beware.)


View raw message