it's not the same but i have the need to create nestet xml elements with data from a data table
the solution was to create a recursive function into my xsp hope that this can help you to figure a solution <?xml version="1.0" encoding="ISO-8859-1"?> <xsp:page language="java" xmlns:xsp="http://apache.org/xsp" xmlns:esql="http://apache.org/cocoon/SQL/v2" xmlns:xsp-request="http://apache.org/xsp/request/2.0"> <xsp:logic> void getChilds(String parent_id, AttributesImpl xspAttr){ try{ <esql:connection> <esql:pool>hotpoints</esql:pool> <esql:execute-query> <esql:query>select * from tblElements WHERE element_Parent=<xsp:expr>parent_id</xsp:expr></esql:query> <esql:results> <esql:row-results> <element> <xsp:logic> parent_id = <esql:get-string column="id_Elements"/>; </xsp:logic> <esql:get-columns/> <xsp:logic> getChilds(parent_id, xspAttr); </xsp:logic> </element> </esql:row-results> </esql:results> <esql:no-results> <the_end>done</the_end> </esql:no-results> </esql:execute-query> </esql:connection> } catch (Exception e) { } } </xsp:logic> <tree> <elements> <xsp:logic> String root_element =<xsp-request:get-parameter name="root_element"/>; getChilds(root_element,xspAttr); </xsp:logic> </elements> </tree> </xsp:page> --stavros On Thu, 18 Dec 2003 [EMAIL PROTECTED] wrote: > Hi, > > Maybe rephrasing the problem makes it clearer: > > I'm building an XSP page that calls a Java Helper class which gets the data > in a hierarchical form. What I'd like to know is: what's the best way of > delivering the result to the calling XSP page without having to traverse the > hierarchy twice. > > Example: > > class MyClass { > public WhichDataType getData() { > <....get data from data source ....> > return result; > } > > When I would serialize the result data it could look like this: > <TopElement> > <ID>some id</ID> > <element> > <name>nameOfElement</name> > <value>someValue</value> > </element> > <element> > <name>anotherElement</name> > <element> > <name>aSubElement</name> > <value>this Element's value</value> > </element> > <element> > <name>This could also be nested</name> > <value>just a simple value</value> > </element> > </element> > </TopElement> > > The "xml" above is not the data I get from the data source, I have to > manipulate it to make it easier to process in Cocoon. If I do that I might > as well use a datatype that I don't have to manually parse again in XSP to > build the above structure using <xsp:element>? > > Does anyone have ideas about the best way to handle this? > > I've thought about putting everything in a long String, but I don't know how > to parse the String in XSP to the corresponding XML. > > Bye, Helma > > > -----Original Message----- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] > > Sent: Thursday, 18 December 2003 16:43 > > To: [EMAIL PROTECTED] > > Subject: How to convert a hierarchical structure to xml in java? > > > > > > Hi, > > > > I'm in the middle of building an XSP page that can retrieve > > information from > > my CORBA-based server. I'm now writing a helper class in Java > > that can take > > the output of the server and transform it into something I > > can easily manage > > in the XSP page. > > However, I'm stuck. The results are in a hierarchical > > structure based on > > Vector and String or String[]. I want to manipulate this > > before returning it > > to the XSP page, but I don't want to traverse the structure for the > > manipulation and then once more in the XSP page to build the XML. > > > > Can anyone help? > > > > Bye, Helma > > > > --------------------------------------------------------------------- > > 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] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
