Hello all,
I would appreciate any help.
Thanks.
I'm new to this mailing list and I'm still learning
everydays about xml in general
I searched for 2 days for my little bug and I
didn't find anything interesting to fix my bug except on Apache Xerces FAQ web
page where it says this error (org.w3c.dom.DOMException: DOM006
Hierarchy request error) appears if I try to add non-whitespace or if I
try to add 2 elements node to my document.
Here is my little source code (using DOM and
Xerces):
By the way, I skipped some sections because I'm
using JSP & servlets and tried to make it easier to
read. ------------------------------------------------------------------------import java.io.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
import org.w3c.dom.Node;
import
org.apache.xml.serialize.XMLSerializer;
import
org.apache.xml.serialize.Serializer;
import
org.apache.xml.serialize.OutputFormat;
import org.apache.xerces.dom.*;
import org.w3c.dom.DOMException;
DocumentImpl doc = new
DocumentImpl(null);
public void myfunction() {
filename =
"1.xml";
Element root=null, style=null, menu=null, menutype=null, eforme=null, ecolor=null; root = (Element)
doc.createElement("siteweb");
menu = (Element) doc.createElement("menu"); eforme = (Element) doc.createElement("eforme"); ecolor = (Element) doc.createElement("ecolor");
eforme.appendChild(doc.createTextNode("text1"));
menu.appendChild(eforme); ecolor.appendChild(doc.createTextNode("text2")); menu.appendChild(ecolor); root.appendChild(menu); doc.appendChild(root); try
{
OutputFormat format = new OutputFormat(doc, "ISO-8859-1", true); FileOutputStream outFile = new FileOutputStream(filename); XMLSerializer serial = new XMLSerializer(outFile, format); serial.asDOMSerializer(); serial.serialize(doc.getDocumentElement()); outFile.flush(); outFile.close(); } catch (IOException e) { out.println(e); } catch (DOMException e) { out.println(e); } }
------------------------------------------------------------------------
As I said, I skipped some sections because I'm
using JSP & servlets and tried to make it easier to read.
Thanks for your help and any
suggestions.
Jean-François Chamard
Horus Technologies Inc.
|