You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Linus Crawford <lc...@etrade.com> on 2000/08/30 00:37:48 UTC
How Do I Create A Dynamic Doc
I need to create a document on the fly and cannot figure out how. I try to:
Document doc = new DocumentImpl();
doc.createElement( "tag1" );
doc.createElement( "tag1n0" );
doc.createTextNode( "some text" );
doc.createElement( "tag1n1" );
doc.createTextNode( "more text" );
seems hunky dory, no exceptions rasised, but when I try to normalize ala
doc.getDocumentElement.normalize();
I get null pointer exception.
doc.getDocumentElement() return seems ok, but if I try to look at the node
it
returned say as in
org.w3c.dom.Node nod = doc.getDocumentElement();
nod.getNodeType()
trying to get it's type, value or name all cause null pointer exception.
Can anyone point me in the right direction??
Thanks in advance, linus@etrade.com
RE: How Do I Create A Dynamic Doc
Posted by Tako Schotanus <qu...@palacio-cristal.com>.
Look at the code in the DOMGenerate.java for example:
Document doc= new DocumentImpl();
Element root = doc.createElement("person"); // Create Root Element
Element item = doc.createElement("name"); // Create element
item.appendChild( doc.createTextNode("Jeff") );
root.appendChild( item ); // atach element to Root
element
item = doc.createElement("age"); // Create another Element
item.appendChild( doc.createTextNode("28" ) );
root.appendChild( item ); // Attach Element to
previous element down tree
item = doc.createElement("height");
item.appendChild( doc.createTextNode("1.80" ) );
root.appendChild( item ); // Attach another
Element - grandaugther
doc.appendChild( root ); // Add Root to Document
> I need to create a document on the fly and cannot figure out how.
> I try to:
> Document doc = new DocumentImpl();
> doc.createElement( "tag1" );
> doc.createElement( "tag1n0" );
> doc.createTextNode( "some text" );
> doc.createElement( "tag1n1" );
> doc.createTextNode( "more text" );
>
> seems hunky dory, no exceptions rasised, but when I try to normalize ala
>
> doc.getDocumentElement.normalize();
>
> I get null pointer exception.
> doc.getDocumentElement() return seems ok, but if I try to look at the node
> it
> returned say as in
>
> org.w3c.dom.Node nod = doc.getDocumentElement();
> nod.getNodeType()
>
> trying to get it's type, value or name all cause null pointer exception.
>
> Can anyone point me in the right direction??
>
> Thanks in advance, linus@etrade.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org