You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Dave Yuill <th...@hotmail.com> on 2001/12/10 20:37:24 UTC

generating DOCTYPE element

Hello,

I'd like to add a DOCTYPE element to the XML I'm generating with xerces, but
cant seem to figure out how...

Right now I have stuff like:

Document doc = new DocumentImpl();
Element root = doc.createElement("test-root");

Element attrElem = doc.createElement("elem-with-attribs");
attrElem.setAttribute("foo", "bar");
root.appendChild( attrElem );

doc.appendChild( root );

// add doctype .. ???

// Serialize DOM and output
...


that creates xml that looks like :
<?xml version="1.0" encoding="UTF-8"?>
<test-root><elem-with-attribs foo="bar"/></test-root>

I'd like it to have a DOCTYPE element.. :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE test-root SYSTEM "http://url.to.my/dtd">
<test-root><elem-with-attribs foo="bar"/></test-root>

Any input would be greatly appericated.
Thanks a bunch,
-Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: generating DOCTYPE element

Posted by Wendi Sisson <ws...@east.fedex.com>.
We did it this way:
            DocumentType documentType = new DocumentTypeImpl(null, null,
null, dtdPath);
            Document requestDOM = new DocumentImpl(documentType);

You have to set the doctype up front. You can't add/change for an
existing Document.

Dave Yuill wrote:
> 
> Hello,
> 
> I'd like to add a DOCTYPE element to the XML I'm generating with xerces, but
> cant seem to figure out how...
> 
> Right now I have stuff like:
> 
> Document doc = new DocumentImpl();
> Element root = doc.createElement("test-root");
> 
> Element attrElem = doc.createElement("elem-with-attribs");
> attrElem.setAttribute("foo", "bar");
> root.appendChild( attrElem );
> 
> doc.appendChild( root );
> 
> // add doctype .. ???
> 
> // Serialize DOM and output
> ...
> 
> that creates xml that looks like :
> <?xml version="1.0" encoding="UTF-8"?>
> <test-root><elem-with-attribs foo="bar"/></test-root>
> 
> I'd like it to have a DOCTYPE element.. :
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE test-root SYSTEM "http://url.to.my/dtd">
> <test-root><elem-with-attribs foo="bar"/></test-root>
> 
> Any input would be greatly appericated.
> Thanks a bunch,
> -Dave
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org

-- 
Wendi Sisson
Systems Programmer
International Trade Development
FedEx Services
(901) 263-6695

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org