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 René Jensen <lu...@tbkol.dk> on 2001/04/10 15:56:57 UTC

building a DOM from scratch...

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
 lundeman@tbkol.dk

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


Re: building a DOM from scratch...

Posted by Birgit Wolter <bi...@gmx.net>.
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:birgit.wolter@gmx.net

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
>  lundeman@tbkol.dk

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



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


Re: building a DOM from scratch...

Posted by Ian Roberts <ir...@decisionsoft.com>.
On Tue, 10 Apr 2001, René Jensen 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...??

You need to use the createElementNS method of the Document object to
create your element nodes, and you can use Element.setAttributeNS to add
attributes to an element.  For example:

Element systemElement = doc.createElementNS("MyNameSpace", "vst:System");
doc.appendChild(systemElement);

etc.

Ian

-- 
Ian Roberts, Software Engineer        DecisionSoft Ltd.
Telephone: +44-1865-203192            http://www.decisionsoft.com




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