[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: generating an DOM object from a non-XML source in Java

  • From: Jurgen <jurgen.moortgat@o...>
  • To: "Newman, Todd" <ToddNewman@T...>
  • Date: Wed, 21 Mar 2001 08:55:53 +0100

new documentimpl

hi,

did you already tried Oracle's xml libraries (you can get them at
technet).

your code may look like this:


    // Construct the new XML Document.
    XMLDocument xmlDoc = new XMLDocument() ;

    // Create the root Node.
    XMLNode rootNode = (XMLNode) xmlDoc.createElement("ROOT") ;

    // Create a new node.
    XMLNode node = (XMLNode) xmlDoc.createElement("TAG") ;
    // Add text to the new node.
    node.appendChild(new XMLText("Value")) ;

   // Append a child to the root tag.
   rootNode.appendChild(node) ;

   /* Repeat the above statements as much as needed (you could make
      this recursive in order to create child and/or parent tags.
   */

   // Append the complete root node (tree) to the new XMLDocument.
   xmlDoc.appendChild(rootNode) ;


cheers,

Jurgen - Oracle Belgium.


"Newman, Todd" wrote:
> 
> Hi,
> 
> 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
> Saxon 6.0.2.
> 
> 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:
>         node1.setNodeValue("Todd")
> ...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!
> 
> thanks,
> Todd
> toddnewman@t...
> 
> ------------------------------------------------------------------
> The xml-dev list is sponsored by XML.org, an initiative of OASIS
> <http://www.oasis-open.org>
> 
> The list archives are at http://lists.xml.org/archives/xml-dev/
> 
> To unsubscribe from this elist send a message with the single word
> "unsubscribe" in the body to: xml-dev-request@l...

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.