[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
generating an DOM object from a non-XML source in Java
- From: "Newman, Todd" <ToddNewman@TDWaterhouse.com>
- To: "'firstname.lastname@example.org'" <email@example.com>
- Date: Tue, 20 Mar 2001 18:28:23 -0500
I've got what I hope is a simple question for the pros. I'm trying to loop
through some delimited text and generate an XML object to end up with a
valid XML object and/or string.
I've been searching the web and my Visual Age online help for the better
part of two days with not much to show for myself. It seems to me that this
should be a common thing to do, but I've not been very successful.
In fact, I've done this several times before in the VB world. My steps in
that universe look like this:
(1) Create the DOMDocument
(2) Load the string "<XML></XML>" into the document
(3) Get a reference to the Document Element
(4) Create Nodes from the DOMDocument
(5) Append the nodes to the Document Element or one of its children
(6) Repeat 4&5 as required
So I've been trying to do something similar with Java. I'm using the
libraries which come with IBM Visual Age for Java, and I also downloaded
First, I tried using com.ibm.xml.dom. With that, I am able to create an
object of type DocumentImpl like so: (step 1)
DocumentImpl di = new DocumentImpl();
Then, I can get a reference to the document element: (step 3)
ElementImpl elRoot = (ElementImpl)di.getDocumentElement();
And I can create an Element: (part of step 4)
NodeImpl node1 = (NodeImpl)di.createElement("T1");
But I can't set the text of the element using:
...without getting an exception (part of step 4.) I also can't append the
node (step 5.) And I can't set call setNodeValue on my root element (step
2), though I don't know if that's important.
So then, I moved on to the com.icl.saxon.tree library. Here I had less
success. I could create the DocumentImpl: (step 1)
DocumentImpl di = new DocumentImpl(1);
And I could create a node: (step 4?)
ElementImpl node1 = new ElementImpl();
But that's as far as I've gotten.
So now I'm stuck and feeling a bit dumb. You might have already figured out
I'm not quite a novice, but far from experienced with Java. Any direction
would be appreciated!