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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
+ XSLT Help and Discussion (7625)
- XQuery Help and Discussion (2017)
-> + Issue with Processing Instruct... (2)
-> + problem converting json to XML... (2)
-> + Problem base64 decoding string... (3)
-> + Problems posting multipart for... (5)
-> + trouble with download of price... (2)
-> + Problem with http-post not bei... (3)
-> + path problem, xps_file:writeAl... (9)
-> + Xquery update support? (2)
-> + problem with Stylus studio try... (5)
-> + adding dtd reference to xml ou... (4)
-> + xquery escaping ambarsand when... (3)
-> + Whitespace problem when return... (5)
-> + Problem with namespace prefix ... (5)
-> - Sending via SFTP returns unexp... (1)
-> + Query and Sftp clent (4)
-> + xquery and try - catch (3)
-> + Query + ddtek:http-post optio... (5)
-> + Example files referenced in do... (3)
-> + Automatic Error Detection and ... (3)
-> + Working with result of ddtek:h... (2)
-- [1-20] [21-40] [41-60] Next
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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

   
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.