Title: RE: building a DOM from scratch...

Using:

Document doc = new DocumentImpl();

should be sufficient to create a new document under Xerces, although the syntax using the DocumentBuilder will work.  Is the setNamespaceAware flag true on default with the BuilderFactory?  I find that I only use the DocumentBuilder/DocumentBuilderFactory when I want to "load" the DOM tree using the DOMParser.

NB:  The approach using the DocumentBuilder/DocumentBuilderFactory is under the javax.xml.parsers package and as such is probably more globally supported than the DocumentImpl which is under the org.apache.xerces.dom package.  However, if you are only going to use xerces, might as well utilize their implementation :-)

S
-----Original Message-----
From: Birgit Wolter [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 10, 2001 7:27 AM
To: Ren� Jensen
Subject: Re: building a DOM from scratch...


Hello Ren�,

try this:

DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbFactory.newDocumentBuilder();
Document document = db.newDocument();
Element root = document.createElementNS("MyNameSapce", "System");
root.setPrefix("vst");
root.setAttribute ("xmlns:vst", "MyNameSpace");
...

document.appendChild (root);

Element error = document.createElementNS("MyNameSpace", "error");
error.setPrefix("vst");
root.appendChild(error);

Birgit                            mailto:[EMAIL PROTECTED]

Tuesday, April 10, 2001, 3:56:57 PM, you wrote:

> Hi there.

> I�m trying to build a DOM from scratch, using the classes supplied in the
> org.apache.xerces.dom package, but I didn't get very far.
> actually I only got to instantiating the DocumentImpl-class cause then i wanted
> to add attributes (namespacedefiniton etc.)

> I thought I should use the AttrNSImpl-class but it only has protected
> constructors. How do I get passed that...??

> What I need is a DOM that I can serialize to this xml-document..

> <?xml version="1.0" encoding="UTF-8"?>
> <vst:System
>    xmlns:vst='MyNameSpace'
>    xmlns:xsi='http://www.w3.org/2000/10/XMLSchema-instance'
>    xsi:schemaLocation='MyNameSpace vSystemTree-Schema.xsd'>
>   <error />
> </vst:System>

> Am I on a totally wrong track, or..??
> plz, I could really need a push in the right direction.

> TIA.
>        _\|/_
>        (@ @)
> ---oOOo-(_)-oOOo---
>     Ren� Jensen
>  [EMAIL PROTECTED]

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to