Thanks, David. Whipping up a schema to associate with the document in question 
turned out to be the easiest solution, and it worked perfectly.

David S.

On Tue, 14 Oct 2014, David Lee wrote:

> There isnt an 'easy' way that I know of.
>
> The reason your docuements are indented nicely is because your XML editor did 
> so, and the indentation (newlines, spaces etc) are already in the file.
>
> You can create such spaces yourself very carefully ... and by making sure the 
> right XQuery options are in set, such as
>
>
>
> declare boundary-space preserve;
>
>
>
> Otherwise even your best attempts will fail ... but that won't *add 
> indentation* ...
>
>
>
> Example:
>
>
>
> declare boundary-space strip;
>
> let $x :=
>
> <foo>
>
>   <bar>
>
>       <spam>  {"a  ccc  xx"}</spam></bar></foo>
>
> return xdmp:document-insert("/test.xml",$x)
>
>
>
>
>
> ---- Now see what the doc looks like with some xml agnostic code ...
>
> This will fool most processors even QC:
>
>
>
> xdmp:quote(doc("/test.xml"))
>
>
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <foo><bar><spam>a  ccc  xx</spam></bar></foo>
>
>
>
> Spaces gone ... boo hoo
>
> now add
>
> declare boundary-space strip;
>
>
>
> and retest
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <foo>
>
>   <bar>
>
>       <spam>  a  ccc  xx</spam></bar></foo
>
>
>
> Better !
>
>
>
> But still you had to put the spaces in the first place.
>
>
>
> To actually get XML "pretty printed" automatically ... you can do a 
> round-trip through xquery or xslt to take advantage of the output indenting 
> formatter (UG !)
>
>
>
> There is one other way I know of -- If you have a schema in-scope then the 
> document is indented    on insert
>
>
>
> Example: I happen to be working on a twitter dump where I have a schema ... 
> The indentation isnt perfect but without a schema
>
> its pretty much impossible to tell what kinds of whitespace  are allowed to 
> be inserted  (that's why ML doesn't do it ...
>
> it can break your data !)
>
>
>
> With a schema in scope ... ML indents ...
>
> you can tell with xdmp:quote() or by getting the file out in text mode
>
>
>
>
>
> let $x :=
>
> <twitter xmlns="http://www.xmlsh.org/schemas/twitter";><status 
> id="298616637173686273"><user created-at="2011-02-04T23:44:43"            
> description=""            lang="en"            name="Martens VW"
>
>            screen-name="martens_vw"><location/></user></status>
>
> </twitter>
>
>
>
> return ( xdmp:document-insert("/test.xml",$x))
>
>
>
>
>
> This proces (with my schema in place)
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <twitter xmlns="http://www.xmlsh.org/schemas/twitter";>
>
>  <status id="298616637173686273">
>
>    <user created-at="2011-02-04T23:44:43" description="" lang="en" 
> name="Martens VW" screen-name="martens_vw">
>
>      <location/>
>
>    </user>
>
>  </status>
>
> </twitter>
>
>
>
> David Lee
>
> Lead Engineer
>
> MarkLogic Corporation
>
> [email protected]
>
> Phone: +1 812-482-5224
>
> Cell:  +1 812-630-7622
>
> www.marklogic.com
>
>
>
> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of David Sewell
> Sent: Tuesday, October 14, 2014 3:57 PM
> To: MarkLogic Developer Discussion
> Subject: Re: [MarkLogic Dev General] xdmp:output serialization options not 
> working?
>
>
>
> Let me restate the problem.
>
>
>
> If I use an editor to manually create this XML document and save it to 
> MarkLogic via WebDav or other means:
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <doc>
>
>   <line>line 1</line>
>
>   <line>line2</line>
>
> </doc>
>
>
>
> then when I subsequently open that document from the database via WebDav or a
>
> doc() call, it arrives with its indentation preserved. I want to know how to 
> generate a new file via XQuery such that it will have indentation when 
> subsquently opened via WebDav or a doc() call.
>
>
>
> (It's not mission-critical, but I'm auto-generating a 50MB data file that I 
> would like to be able to open in oXygen via WebDav with its elements already 
> indented, since thing go much faster that way.)
>
>
>
> DAvid
>
>
>
> On Tue, 14 Oct 2014, Mary Holstege wrote:
>
>
>
>> On Tue, 14 Oct 2014 12:28:52 -0700, David Sewell
>
>> <[email protected]<mailto:[email protected]>>
>
>> wrote:
>
>>
>
>>> Given this code:
>
>>>
>
>>> xquery version "1.0-ml";
>
>>> declare option xdmp:output "indent-untyped=yes"; declare option
>
>>> xdmp:output "omit-xml-declaration=yes"; xdmp:document-insert(
>
>>>    "/test.xml",
>
>>>    <doc>
>
>>>      <line>line 1</line>
>
>>>      <line>line2</line>
>
>>>    </doc>
>
>>> ) ;
>
>>>
>
>>> doc("/test.xml")
>
>>>
>
>>> The output I'm getting is
>
>>>
>
>>> <?xml version="1.0" encoding="UTF-8"?> <doc><line>line
>
>>> 1</line><line>line2</line></doc>
>
>>>
>
>>> which is disobeying both serialization optinons I specified. ML
>
>>> version 7.0-4.
>
>>> Are other people seeing this? Am I missing something?
>
>>>
>
>>> David
>
>>>
>
>>
>
>>
>
>> Two things:
>
>> (1) If you are running this in QConsole all bets are off, because the
>
>> serialization options apply in the query that does the serialization
>
>> and everything in QConsole is run in a separate eval.
>
>>
>
>> (2) The serialization options are before the semi-colon, that is, they
>
>> only apply to the xdmp:document-insert part of this file. If you want
>
>> them to apply to the serialization of doc("/test.xml") you need to put
>
>> them into that query.
>
>>
>
>> //Mary
>
>> _______________________________________________
>
>> General mailing list
>
>> [email protected]<mailto:[email protected]>
>
>> http://developer.marklogic.com/mailman/listinfo/general
>
>>
>
>
>
> --
>
> David Sewell, Editorial and Technical Manager ROTUNDA, The University of 
> Virginia Press PO Box 400314, Charlottesville, VA 22904-4314 USA
>
> Email: [email protected]<mailto:[email protected]>   Tel: +1 434 924 
> 9973
>
> Web: http://rotunda.upress.virginia.edu/
>
> _______________________________________________
>
> General mailing list
>
> [email protected]<mailto:[email protected]>
>
> http://developer.marklogic.com/mailman/listinfo/general
>

-- 
David Sewell, Editorial and Technical Manager
ROTUNDA, The University of Virginia Press
PO Box 400314, Charlottesville, VA 22904-4314 USA
Email: [email protected]   Tel: +1 434 924 9973
Web: http://rotunda.upress.virginia.edu/
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to