Blake Milam
Blake Milam

Reputation: 31

MarkLogic is losing my line breaks in .xqy files when inserting via curl PUT

Anytime I add an xquery script using curl, the resulting file on the server loses all page breaks and some whitespace. This causes lines to run together and some words to run together. This is causing the script to fail due to reserved words getting concatenated with others.

The command I'm using is this:

curl --anyauth --user username:password -X PUT -d @"./badactorasset-lib.xqy" -i -H "Content-type: application/xquery" http://localhost:8004/v1/ext/badactor/badactorasset-lib.xqy

When I browse other .xqy files on the MarkLogic server through the Query Console, those file display with lines breaks perfectly. The files I add are all missing line breaks and look unreadable.

***Example of another file that was loaded in the past on to the server:

xquery version "1.0-ml";
module namespace ba = "http://marklogic.com/badactor/badactor";
declare option xdmp:mapping "false";
declare variable $ba:ETYPES := ("HX", "FER", "RER", "ELEC", "INSTR");
declare function ba:get-duration($type as xs:string) as xs:yearMonthDuration
{
  let $years :=
    if ($type eq "HX") then 5
    else if ($type eq "FER") then 10
    else if ($type eq "RER") then 2
    else if ($type eq "ELEC") then 10
    else if ($type eq "INSTR") then 2
    else 0
  return xs:yearMonthDuration("P" || fn:string($years) || "Y")
};

***Example of my file on the server:

xquery version "1.0-ml";module namespace ba = "http://marklogic.com/badactor/badactorasset";declare option xdmp:mapping "false";declare variable $ba:ETYPES := ("HX", "FER", "RER", "ELEC", "INSTR");declare function ba:get-duration($type as xs:string) as xs:yearMonthDuration{  let $years :=    if ($type eq "HX") then 5    else if ($type eq "FER") then 10    else if ($type eq "RER") then 2    else if ($type eq "ELEC") then 10    else if ($type eq "INSTR") then 2    else 0  return xs:yearMonthDuration("P" || fn:string($years) || "Y")};declare function ba:get-threshold($type as xs:string) as xs:integer{   if ($type eq "INST

What am I missing? Why are my files losing their structure?

Upvotes: 1

Views: 132

Answers (1)

Blake Milam
Blake Milam

Reputation: 31

I found the issue deep in some documentation unrelated to MarkLogic.

I should use the "--data-binary" flag instead of the default "-d" flag in order to preserve line breaks. This isn't discussed on MarkLogic's site or in any of their examples, but it fixed my files.

Here's the full curl command now:

curl --anyauth --user username:password -X PUT --data-binary @"./badactorasset-lib.xqy" -i -H "Content-type: application/xquery" http://localhost:8004/v1/ext/badactor/badactorasset-lib.xqy

Upvotes: 2

Related Questions