Frage

I have a few working XQuery scripts that I would like to use to generate valid XML documents. Therefore I would also like to include an XML header: <?xml version="1.0" encoding="UTF-8"?>. I am aware that this header is optional but I want it to be included regardless, especially to specify the right encoding.

However, I'm at a loss as to how I would insert this header into the output. My editor (XMLSpy) complains on any variation I can think of to insert the header.

According to the few resources I've found on this, it may be that I'm not supposed to generate this header manually, but rather let my serializer do this for me, possibly by setting interpreter options with declare option. I can't find any information on this when it comes to XMLSpy however.

Is there a way to insert this header manually? If not, do I need to modify my interpreter so it is generated automatically?

War es hilfreich?

Lösung

Presuming you're using AltovaXML for executing your xquery, you need to set omitXMLDeclaration to false (the default is true) through whatever interface you're executing it with - command line, java, or whatever. There does not appear to be a xquery-level option declaration to set this. The docs at http://manual.altova.com/AltovaXML/altovaxmlcommunity/ show how to do it for each of the various cases.

Andere Tipps

I think the declare options are implementation specific, so you'd need to look up the correct option for your xQuery processor. For example:

Saxon:

declare option saxon:output "omit-xml-declaration=no";

Marklogic:

declare option xdmp:output "omit-xml-declaration=no";

However, you should be able to manually output the prolog by prepending this to your output:

<?xml version="1.0" encoding="UTF-8" ?>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top