Just tried the following and works fine:
try {
Document doc= new DocumentImpl();
Element root = doc.createElement("person"); // Create Root E
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 E.
item.appendChild( doc.createTextNode("28" ) );
root.appendChild( item ); // Attach Element to previous element
item = doc.createElement("height");
item.appendChild( doc.createTextNode("1.80" ) );
root.appendChild( item ); // Attach another Element - grandaugther
doc.appendChild( root ); // Add Root to Document
OutputFormat format = new OutputFormat( doc );
StringWriter stringOut = new StringWriter();
XMLSerializer serial = new XMLSerializer( stringOut, format );
serial.serialize( doc.getDocumentElement() );
System.out.println( "STRXML = " + stringOut.toString() );
} catch( Exception ex )
{
ex.printStackTrace();
}
}
I generate a DOM from scratch and print it out in XML using the
serializer.
You said that it did work for you. What did not work for you?
Could you be more explicit? Did you get an error?
Thanks,
Jeffrey Rodriguez
XML Development
IBM Cupertino
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com