By "struct" I think you mean you want an element node.
 
Your query selects a sequence of "racine" elements, and the iteration over "books" assigns each one of these to the variable "book" in turn. You are then extracting the string value - which is the concatenation of the text node descendants of the "racine" element.
 
When you say you want the "struct", it's not clear to me what you mean. Do you want the element as an object? You've got that in the "book" item. Or do you want the element serialized as XML, in a string, that is "<book>abc</book>" as a string of 16 characters? In that case you need to serialize the item.
 
The simplest way to do this is probably:
 
QueryResult.serialize((NodeInfo)book, new StreamResult(System.out), new Properties(), config);
 
If you want this in a variable, use
 
StringWriter writer = new StringWriter()
 
and new StreamResult(writer) as the second argument.
 
Michael Kay
http://www.saxonica.com
 


From: saxon-help-admin@lists.sourceforge.net [mailto:saxon-help-admin@lists.sourceforge.net] On Behalf Of Benjamin Garoby
Sent: 11 October 2005 10:28
To: saxon-help
Subject: [saxon] Xquery: obtain an Xml Struct?

Hello,
 
I use Xquery with Saxon.
My code is :
 
Configuration config = new Configuration();
        StaticQueryContext staticContext = new StaticQueryContext(config);
        try {
        XQueryExpression exp = staticContext.compileQuery("//racine");
        DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
        dynamicContext.setContextNode(staticContext.buildDocument(
                    new StreamSource(new File("D:\\fichiersTest\\transform1.xml"))));
       SequenceIterator books = exp.iterator(dynamicContext);
       while (true) {
            Item book = books.next();
            if (book==null) break;
            vCalculValue = book.getStringValue();
            System.out.println(vCalculValue);}
 
This is run correctly but i would like an Xml Struct and not just the value in my final variable . i would like "<book>XML book</book>" and not just "XML book"
 
Is it a solution?
 
thks
 
benjamin 
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.