qexo-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qexo-general] toString() on result from eval()


From: Alessandro Vernet
Subject: [Qexo-general] toString() on result from eval()
Date: Thu, 22 May 2003 11:10:46 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3) Gecko/20030312

Hi,

Using toString() on the result of an XQuery.eval() sometimes leads to unexpected results. Using the XMLPrinter works fine in those cases. Consider the following example:

-----------------------------------------------------
import gnu.xquery.lang.XQuery;
import gnu.xml.XMLPrinter;

import java.io.StringWriter;

public class Test {
    public static void main(String[] args) {
        try {
            XQuery xquery = new XQuery();
            Object result = xquery.eval
                ("let $a := doc('gaga.xml')/* return <a>{$a}</a>");
            System.out.println("Using toString(): ->"
                + result + "<-");
            StringWriter stringWriter = new StringWriter();
            new XMLPrinter(stringWriter).writeObject(result);
            System.out.println("Using XMLPrinter: ->" + stringWriter
                + "<-");
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
    }
}
-----------------------------------------------------

The output is:
Using toString(): -><a>address@hidden ipos: 12}</a><-
Using XMLPrinter: -><a><gaga /></a><-

One would expect the toString() to return an XML fragment equivalent to the one returned using the XMLPrinter.

Alex





reply via email to

[Prev in Thread] Current Thread [Next in Thread]