cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brett D. McLaughlin" <new.insta...@gte.net>
Subject Re: JDOM and Thank You :)
Date Thu, 27 Apr 2000 17:45:27 GMT
Mike Engelhart wrote:
> 
> Brett D. McLaughlin wrote:
> 
> > JDOM is an /alternative/ to DOM and SAX.  It provides a fast,
> > Java-optimized method of reading, writing, and manipulating XML.  (Btw,
> > the PowerPoint slides just went up on the website - check
> > download/docs.  PDF coming in an hour or so).  DOM is trying to be a
> > cross-platform, 100% accurate representation of an XML document.  We
> > don't believe that in most cases, Java developers need that.  THey want
> > an intuitive, usable means of accessing XML data.
> >
> > For example:
> >
> > <dom-code>
> > // This does *not* work, even though it is intuitive
> > String elementValue = element.getValue();
> > // This works (most of the time!)
> > String elementValue = element.getFirstChild().getValue();
> > </dom-code>
> awww yeah!!!
> 
> Thanks for this!  I hated the W3C DOM API!!!! Apparently you and Jason did
> too :-)

I had to write a whole book on it, so more than you can imagine ;-)

> 
> one question -have you tested it's interoperability with Cocoon 1.x (and/or
> 2.x)??

not yet - we just released the API this morning, actually, so we are a
bit thin on help - come help out!  We can use it!

> Scenario:
> I'm about to rewrite some code to take data from a result set and want to
> put it directly into an XML fragment rather than an intermediate ArrayList.
> Can I use JDOM for this and hand a Node off to an XSP page for further
> processing using Xerces??  Please??? :-)

Does XSP need a DOM tree as input, or what?  We haven't written the
DOMOutputter class, but have a DOMBuilder, so just need to reverse the
flow.  Wouldn't take but maybe an hour or two, and it is something we
need to add anyway... but yes, it sounds like JDOM is a great solution
to your problem.  Very simple to do with JDOM:

Document doc = new Document(new Element("myRoot"));

doc.getRootElement()
 .addChild(new Element("row")
    .addChild(new Element("fname")
      .setContent("Brett"))
    .addChild(new Element("lname")
      .setContent("McLaughlin"))
    .addChild("email")
      .addAttribute("type", "POP")
      .setContent("brett@jdom.org"))
    )
 .addChild(new Element("row")
    .addChild(new Element("fname")
      .setContent("Brett"))
    .addChild(new Element("lname")
      .setContent("McLaughlin"))
    .addChild("email")
      .addAttribute("type", "POP")
      .setContent("brett@jdom.org"))
    )
  );

DOMOutputter fmt = new DOMOutputter(myDOMTree);
fmt.output

// or maybe
DOMOutputerr fmt = new DOMOutputter();
org.w3c.dom.Document doc = fmt.output();

Either way, I hope you see how easy this is ;-)

Hop onto jdom-interest (visit jdom.org and select mailing lists), and we
can carry on further there, then when you have the components, we can
jump back to Cocoon-land.

-Brett

> 
> thanks again...
> 
> mike

Mime
View raw message