XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Steven FancherSubject: Omiting the XML declaration from Xqueries
Author: Steven Fancher
Date: 26 Mar 2006 02:35 PM
All,

I've been feeding some simple Xqueries to the SAXON parser from a java class. Works like a charm. However, I'd like the output to exclude the standard <?xml version="1.0" encoding="ISO-8859-1"?> declaration.

When I run the query in StylusStudio the result does not contain the declaration, but when I run it from java I get the decl. There seem to be references to an omit-xml-declaration setting but the only place I see it is in stylesheets.

I can just post-process the results in Java of course, but that seems architecturally offensive......

I also get that this is not strictly an XML problem, but a serializer problem. None the less I can't figure out how to do it, so I figured I' ask people smarter than I :-)

(BTW any other random criticizims of the code below are welcome!)

The Java class that makes the call is below:
============================================
// run an Xquery against a saxon document
public static String runQuery(net.sf.saxon.jdom.DocumentWrapper doc,
String query) {

// the result
ByteArrayOutputStream os = new ByteArrayOutputStream();
StreamResult result = new StreamResult(os);

// stores saxon internals
final Configuration config = new Configuration();

try {
// set up the query
final StaticQueryContext sqc = new StaticQueryContext(config);
final XQueryExpression exp = sqc.compileQuery(query);

// wire in the passsed node as source
final DynamicQueryContext dynamicContext =
new DynamicQueryContext(config);
dynamicContext.setContextItem(doc);

// run the query
exp.run(dynamicContext, result, new Properties());
} catch (Exception e) {
e.printStackTrace();
}
return os.toString();
}

Postnext
Minollo I.Subject: Omiting the XML declaration from Xqueries
Author: Minollo I.
Date: 26 Mar 2006 10:34 PM
You can try adding this to your XQuery:

declare namespace saxon="http://saxon.sf.net/";
declare option saxon:output "omit-xml-declaration=yes";

Or you may want to take a look at the Java code generated by Stylus Studio for XQuery/Saxon (XQuery > Generate Java Code); it looks like it never generates the XML PI.

Hope this helps,
Minollo

Postnext
Steven FancherSubject: Omiting the XML declaration from Xqueries
Author: Steven Fancher
Date: 27 Mar 2006 09:22 AM
M,

Thanks - worked like a charm. Couldn't for the life of me figure out the syntax to do that in saxon. Can you apss a pointer to where it is documented?

Again, Thanks!

Posttop
Minollo I.Subject: Omiting the XML declaration from Xqueries
Author: Minollo I.
Date: 27 Mar 2006 09:34 AM
http://www.saxonica.com/documentation/extensions/output-extras.html
+ some fantasy...

Minollo

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.