-stephan
Hervé Guidetti wrote:
002301c05f6b$aff285a0$[EMAIL PROTECTED]">Thanks a lot.
Now it works. In fact, I realized that I had an very old version of Xerces
(1.1.3) !
Sorry for that.
Your method documentToString seams to be cool. Is it possible to get the
class ??
Thanks for your help.
Hervé
----- Original Message -----
From: Stephan Nagy <[EMAIL PROTECTED]>
To: ECS <[EMAIL PROTECTED]>
Sent: Tuesday, December 05, 2000 10:32 PM
Subject: Re: How to transform XML to org.w3c.DocumentI changed the createDOM() to return a document, why I had it returning a
nodelist i don't know. The following worked for me.
PI p = new PI();
p.setVersion(1.0);
XML x = new XML("root",true);
XML x1 = new XML("page",true);
XML x2 = new XML("paragraph");
XML x3 = new XML("paragraph");
x2.addElement("This is the first Paragraph");
x3.addElement("This is the second Paragraph");
x.addElement(x1.addElement(x2).addElement(x3));
p.addElement(x);
DOMFactory d = new DOMFactory();
p.output(d.getOutputStream());System.out.println(DocumentFactory.getInstance().documentToString(d.createDO
M(),true));DocumentFactory.getInstance().documentToString(dom,indent) is a
convience method in a local class here to stringify org.w3c.dom.Document
the resulting output is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<page>
<paragraph>This is the first Paragraph</paragraph>
<paragraph>This is the second Paragraph</paragraph>
</page>
</root>
-stephan
Hervé Guidetti wrote:I was a bit to hurry. In fact it works only for the first child.
I tried the code in the JavaDoc but page is null.
:-(
This is my code.
public static NodeList convertXMLtoNodeList(XML theXML) throws Exception
{
PI p = new PI();
p.setVersion(1.0);
p.addElement(theXML);
DOMFactory d = new DOMFactory();
p.output(d.getOutputStream());
NodeList nl = d.c! reateDOM();
return nl;
}
public static void main(String[] args)
{
XML x = new XML("root", true);
XML x1 = new XML("page", true);
XML x2 = new XML("paragraph");
XML x3 = new XML("paragraph");
x2.addElement("This is the first Paragraph");
x3.addElement("This is the second Paragraph");
x.addElement(x1.addElement(x2).addElement(x3));
try
{
NodeList nl = convertXMLtoNodeList(x);
org.w3c.dom.Node root = nl.item(1);;
org.w3c.dom.Node page = root.getFirstChild();
org.w3c.dom.Node paragraph1 = page.getFirstChild();
String text = paragraph1.getNodeValue();
}
catch (Exception e)
{
e.printStackTrace();
}
}
Is there something I do wrong ??
Any idea ??
Hervé
----- Original Message -----
From: Hervé Guidetti
To: ECS
Sent: Tuesday, December 05, 2000 5:50 PM
Subject: Re: How to transform XML to org.w3c.Document
Ooooooooooh yes,It works.
Thanks a lot
:-))
Hervé
----- Original Message -----
From: Stephan Nagy
To: ECS
Sent: Tuesday, December 05, 2000 4:45 PM
Subject: Re: How to transform XML to org.w3c.Document
Use the org.apache.ecs.factory.DOMFactory it requires xerces to beinstalledand in the classpath but it will do the trick.
-stephan
Hervé Guidetti wrote:
Hi,
I want to use ecs to create an XML tree (using the XML class).
After creating this tree, I want to parse it.
In fact, I need to transfom the org.apache.ecs.xml.XML to a
org.w3c.Document.
Do you have an idea how to do this ?
Thanks,
Hervé
--
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Archives and Other: <http://java.apache.org/main/mail.html>
Problems?: ! [EMAIL PROTECTED]
--
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Archives and Other: <http://java.apache.org/main/mail.html>
Problems?: [EMAIL PROTECTED]
--
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Archives and Other: <http://java.apache.org/main/mail.html>
Problems?: [EMAIL PROTECTED]
