file:write(...) is not respecting indent parameter correctly
Monday, 1 July 2024 · 3 messages · last reply 2 Jul 2024
Y
ykhabins1 Jul 2024 19:30 #
Hello,
I am using the latest BaseX 11.0 final.
It looks like that
file:write(...) is not respecting indent parameter correctly: 'indent': 'yes'
Split.xq
========================
declare variable $input as xs:string external;
declare variable $output_dir as xs:string external;for $x at $i in doc($input)/Events/Event
return file:write($output_dir || file:dir-separator() || "event_" || $i ||
".xml", $x
, map {'method': 'xml', 'indent': 'yes', 'omit-xml-declaration': 'no'})
========================
Input.xml
========================
<?xml version="1.0" encoding="utf-8"?>
<Events>
<Event><CaseNumber>22-0000124</CaseNumber>
<EventDate>2022-04-16</EventDate>
<AgencyORINum>ATF000001</AgencyORINum>
<CrimeType>ROBBERY</CrimeType>
</Event>
<Event><CaseNumber>22-0000125</CaseNumber>
<EventDate>2022-04-16</EventDate>
<AgencyORINum>ATF000001</AgencyORINum>
<CrimeType>ROBBERY</CrimeType>
</Event>
</Events>
========================Regards,
Yitzhak Khabinsky
Y
ykhabins2 Jul 2024 19:36 #
The solution was to add a stripws option.
After that all output XML files are indented properly because causing the issue whitespaces were removed.
Please see the working properly XQuery below.
(: https://docs.basex.org/main/Options#stripws :)
declare option db:stripws "true";
declare variable $input as xs:string external;
declare variable $output_dir as xs:string external;
for $x at $i in doc($input)/Events/Event
return file:write($output_dir || file:dir-separator() || "event_" || $i ||
".xml", $x
, map {'method': 'xml', 'indent': 'yes', 'omit-xml-declaration': 'no'})Regards,
Yitzhak Khabinsky
CG
Christian Grün2 Jul 2024 20:34 #
…that’s it. Another solution is to use
fetch:doc: fetch:doc($input, { 'stripws': true() })With XQuery 4, the standard
fn:doc function may be extended with an options argument. If so, the fetch namespace prefix can be omitted.Quoted text · ykhabins · 25 lines
<ykhabins at bellsouth.net> schrieb am Di., 2. Juli 2024, 17:36: > The solution was to add a stripws option. > After that all output XML files are indented properly because causing the > issue whitespaces were removed. > Please see the working properly XQuery below. > > > (: https://docs.basex.org/main/Options#stripws :) > declare option db:stripws "true"; > > declare variable $input as xs:string external; > declare variable $output_dir as xs:string external; > > for $x at $i in doc($input)/Events/Event > return file:write($output_dir || file:dir-separator() || "event_" || $i || > ".xml", $x > , map {'method': 'xml', 'indent': 'yes', 'omit-xml-declaration': 'no'}) > > > > Regards, > Yitzhak Khabinsky > > >
Written for BaseX 11.0. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery