An example says it all:
declare option output:indent 'no'; document { <a><b/></a> }
Output: <a><b/></a>
declare option output:indent 'yes'; document { <a><b/></a> }
Output: <a> <b/> </a>
More details about serialization can be found in our wiki [1].
Regards, Dimitar
[1] http://docs.basex.org/wiki/Serialization
Am Freitag, 25. Mai 2012, 10:20:49 schrieb Godmar Back:
Hi,
I'm confused about whitespace. I've written an XQuery that returns an XML fragment based on some computation on an underlying XML document. The returned XML contains insignificant whitespace, which then adversely affects my program. I'm not sure if I'm causing it or BaseX, or even what the rules are.
My XQuery contains code such as this one (I'm using color to emphasize the relevant parts).
declare function local:buildSubTree($id) { let $feed := doc($doc_name)/atom:feed let $parent := $feed/atom:entry[atom:id=$id] let $children := data($parent//libx:entry/@src) return if (fn:count($children) = 0) then () else for $child_id in $children return if (local:isInThisFeed($feed, $child_id)) then <node id='{$child_id}' type='{local:getType($feed, $child_id)}' title='{local:getTitle($feed, $child_id)}'>{ local:buildSubTree($child_id) }</node> else if (functx:is-absolute-uri($child_id)) then <node id='{$child_id}' title='Unpublished Entry' type='external' /> else <node id='{$child_id}' title='Unpublished Entry' type='import' /> };
but the result contains fragments such as this, which is an 2-space indented formatting of the XML, with insignificant whitespace added:
<node id="180" title="Put Google Book results into Addison"
type="libapp"> <node id="181" title="Search Google Books while searching Addison" type="module"/> <node id="182" title="Display HTML notifications via an embedded panel using jGrowl" type="module"/> </node>
If I say <node>{ ... }</node> in the XQuery etc., should there be insignificant whitespace in the response?
Thank you for any help/pointers.
(Note that I have considered simply stripping insignificant whitespace, but I do not like this solution since for some queries, I'd like to preserve it, whereas for others I absolutely cannot have insignificant whitespace since I'm performing traversals of the resulting XML DOM Tree.)
Thank you!
- Godmar