I am trying to perform a basic document insert using the XQJ API communicating with a standalone BaseXServer.  I have a lot of dependencies on my classpath (I'm sure this affects JAXP's behavior), including Saxon, Xerces, Xalan, and probably a few versions of some of them.  When I set the transformer factor explicitly to Xalan, there is no exception, but otherwise it appears Saxon is being used and it down throw an exception.  I have a very high opinion of Saxon so I have my doubts that it's doing anything illegal with respect to the standards, so I thought I should ask what is going on.  This is the property I can set to get rid of the problem:

System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.processor.TransformerFactoryImpl");

Here is the exception and stack trace:

javax.xml.xquery.XQException:

  XQJTO013 - Values of 'standalone' and 'omit-xml-declaration' conflict

  Root Cause:

  net.sf.saxon.trans.XPathException: Values of 'standalone' and 'omit-xml-declaration' conflict

  at MyClass.main(MyClass.java:82

  at net.sf.saxon.serialize.XMLEmitter.writeDeclaration(XMLEmitter.java:226)

  at net.sf.saxon.serialize.XMLEmitter.openDocument(XMLEmitter.java:143)

  at net.sf.saxon.serialize.XMLEmitter.startElement(XMLEmitter.java:303)

  at net.sf.saxon.event.NamespaceReducer.startElement(NamespaceReducer.java:72)

  at net.sf.saxon.event.ReceivingContentHandler.startElement(ReceivingContentHandler.java:290)

  at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)

  at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)

  at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)

  at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)

  at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)

  at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)

  at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)

  at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)

  at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)

  at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)

  at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:400)

  at net.sf.saxon.event.Sender.send(Sender.java:154)

  at net.sf.saxon.IdentityTransformer.transform(IdentityTransformer.java:35)

  at MyClass.main(MyClass.java:82)


And here is the relevant code:

XQDataSource xqs = new BaseXXQDataSource();

xqs.setProperty("serverName", "localhost");

xqs.setProperty("port", "1984");

XQConnection conn = xqs.getConnection("admin", "admin");

try {

XQStaticContext context = conn.getStaticContext();

XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(new FileReader(args[0]));

XQPreparedExpression xqpe = conn.prepareExpression("declare namespace output = \"http://www.w3.org/2010/xslt-xquery-serialization\";declare option output:omit-xml-declaration \"no\";declare variable $doc external;\nfn:put($doc,\"jc003.xml\")", context);

//xquery doc('oguns/jc001.xml')

try{

xqpe.bindDocument(new QName("doc"), xmlReader, conn.createDocumentType());

XQResultSequence xqrs = xqpe.executeQuery();

} finally {

xqpe.close();

}

}

finally {

conn.close();

}