Hi Mark,
I'm using flow to create and modify an xml document which I then send through a pipeline for display.
I've forgotten where I pinched the code from but here's an example:


importClass(org.apache.xpath.XPathAPI); importClass(javax.xml.parsers.DocumentBuilderFactory); importClass(org.w3c.dom.Node);
importClass(org.w3c.dom.Element);
importClass(org.w3c.dom.NodeList);


function newDocument(root, attributeName, attributeVal) {
var result = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();


   // Create a processing instruction targeted for xml.
   var node = result.createProcessingInstruction("xml", "version='1.0'");
   result.appendChild(node);
   node = null;

// Create a comment for the document.
node = result.createComment(
"sample xml file created using XML DOM object.");
result.appendChild(node);
node=null;


result.appendChild(result.createElement(root));
print("Add attributes to root..." + attributeName);
if (attributeVal != null){
try {
print("creating attribute for root: " + attributeName); var root = result.getFirstChild();
root.setAttribute(attributeName, attributeVal);


} catch (error) {
cocoon.log.error("Could not add attribute node to root: " + error);
}
}


return result;
}
To load an existing document I use this:
// Load a document from an URI, absolute or relative to the current sitemap
function loadDocument(uri) {
var resolver = cocoon.getComponent("org.apache.excalibur.source.SourceResolver");
var source = resolver.resolveURI(uri);
try {
document = Packages.org.apache.cocoon.components.source.SourceUtil.toDOM(source);
} finally {
resolver.release(source);
cocoon.releaseComponent(resolver);
}
return document;
}


I then add the document to the session:
var sessionManager = cocoon.getComponent("org.apache.cocoon.webapps.session.SessionManager");
var session = sessionManager.getSession(true);
session.setAttribute("hrcyDoc", hrcyDoc);
cocoon.sendPage("tree-menu");


the last step (sendPage("tree-menu")) renders the document as a tree using xslt.
I can't attest as to its efficiency but it seems to go OK so far. I've got a whole bunch of other functions to add, move, copy nodes and attribute etc.
If you need any of this, let me know and I'll send it to you.


Regards,
Tony

Mark Lundquist wrote:

Hi,

I need a cocoon pipeline to serve up an XML stream obtained from a back-end object. I'd like to avoid writing a generator if possible. How would I write this using just flow + my POJO?

Thanks a lot,
Mark


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to