[xquery-talk] how to construct XML via strings

Jonathan Robie jonathan.robie at datadirect.com
Mon Oct 2 14:07:48 PDT 2006

Hi Maxim,

If I understand you correctly, you want to access the results as a 
string, and you want to avoid a possible performance hit from building 
an object structure to represent the result, but logically, you are 
building XML. Did I get that right?

If so, I think your gripe is not with XQuery, but with the way results 
are build and represented physically in the environment. If you are 
operating in a Java environment, why not use XQJ to issue an XQuery, 
then stream the results as text? Depending on what you are trying to do, 
you might be able to use an external variable to specify content for the 
XML you want to build, e.g.instead of:


Write an XQuery that takes the content as an external variable:

declare variable $content external;
<a>{ $content }</a>

In XQJ, bind the external variable before executing the query, and 
retrieve results as text:

XQDataSource dataSource = new DDXQDataSource();   
XQConnection connection = dataSource.getConnection();

FileReader fileReader = new
XQPrepared Expression preparedExpression =
preparedExpression.bindString(new QName("content"), "123");
XQSequence xqSequence = preparedExpression.executeQuery();
OutputStream o_stream = new FileOutputStream("output.xml");

> It also seems that Michael Kay is right that it is one of the most
> problematic features of XQuery. 

Well, he actually said providing this feature in XSLT 1.0 was 
problematic, so the feature was dropped in XSLT 2.0. This feature has 
never been part of XQuery. I don't think he was suggesting that the lack 
of this functionality has been a problem in XQuery.

> We are developing our own XQuery
> implementation called Sedna and we cannot understand how we can extend
> XQuery in a natural way to support the feature.
Can you say more about who would use this feature how in your 
environment? It might help us think of alternative designs.


Read my Blog: http://blogs.datadirect.com/jonathan_robie/
Learn XQuery: http://media.datadirect.com/download/docs/ddxquery/tutorial_query.html
Learn XQJ (the JDBC for XQuery): http://www.datadirect.com/developer/xquery/topics/xqj_tutorial/
Get DataDirect XQuery: http://www.datadirect.com/products/xquery/

More information about the talk mailing list