0

I am using xqj api for implemeting XQuery in java, the following is a sample query I have got and it does work. I need to write the output of the query into a .xml file , any one help me in this please?

String queryString =

            "declare variable $docName as xs:string external;" + sep +
            "for $cat in doc($docName)/*/"+ objectName +
             "    where $cat/"+field+" > "+ value +
               " order by $cat/" + field + " "+
            "return $cat";
            XQExpression expression = conn.createExpression();
            expression.bindString(new QName("docName"), filename,
            conn.createAtomicType(XQItemType.XQBASETYPE_STRING));
            XQSequence results = expression.executeQuery(queryString);
            System.out.println(results.getSequenceAsString(new Properties()));
4

1 回答 1

1

尝试这个:

XQSequence results = expression.executeQuery(queryString);
FileOutputStream os = new FileOutputStream(new File("output.xml");
results.writeSequence(os, new Properties());
于 2012-06-23T07:53:46.707 回答