xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "aaz" <...@webcapacity.com>
Subject Re: re: dumb question
Date Tue, 17 Apr 2001 15:39:02 GMT
thanks, I tried that "d.appendChild(e)"  but get

EXCEPTION: org.w3c.dom.DOMException: DOM006 Hierarchy request error



----- Original Message -----
From: <Shane_Curcuru@lotus.com>
To: <general@xml.apache.org>
Sent: Tuesday, April 17, 2001 8:14 AM
Subject: re: re: dumb question


>
> This would be funny if it weren't so simple! (and such a frequent kind of
> question)  Given your code below, that does look to be the correct output.
>
> Of course, you're wondering: what the heck is going on?  This would seem
to
> be right...  To add information to a DOM Document, you have to create the
> elements and attributes, and *then* *add* them to the document itself.
The
> call:
>     Element e = d.createElement("TestElement");
> merely creates an element that you can use, but does *not* stick it into
> the Document d.  You have to do that yourself with something like:
>     d.appendChild(e);
>
> So one follow on question is: what are people's favorite sets of example
> code for how to do common XML-oriented programming?  I know there are
> plenty of books, etc., but what's your favorite either online source or
> even better, sample program hosted at Apache for programming hints?
>
> - Shane
>
> ---- you "aaz" <aaz@webcapacity.com> wrote ----
> Hi all,
> Thanks for the start, I tried this after looking at the java docs but get
> the following as the result:
> Not what I am expecting I guess given my code below, is this correct?
>
> <?xml version="1.0" encoding="UTF-8" ?>
>   <TestRoot />
> -----------------------------------------------------
>
>
>         org.w3c.dom.DOMImplementation di  =
(org.w3c.dom.DOMImplementation)
> new org.apache.xerces.dom.DOMImplementationImpl();
>         org.w3c.dom.Document d = di.createDocument(null,"TestRoot",null);
>
>         org.w3c.dom.Attr attr = d.createAttribute("attr1");
>         attr.setValue("testval");
>
>         org.w3c.dom.Element e = d.createElement("TestElement");
>         e.setAttributeNode(attr);
>
>         DOMSource dsource = new DOMSource(d);
>         File f = new File("c:/Test.xml");
>         f.createNewFile();
>         StreamResult st = new StreamResult(f);
>
>         TransformerIdentityImpl ti =  new TransformerIdentityImpl();
>         Transformer t = ti.getTransformer();
>         t.transform(dsource,st);
>
>
>
>
>
>
> ---------------------------------------------------------------------
> In case of troubles, e-mail:     webmaster@xml.apache.org
> To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
> For additional commands, e-mail: general-help@xml.apache.org


---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Mime
View raw message