2015-11-26 43 views
0

我有一個表單有問題,我可以縮小到下面的 。它的類型是多部分/格式數據的一個POST,將一個文件 部分:以XML節點檢索多部分/表單數據文件

------------------------------ed0cb8f98262 
Content-Disposition: form-data; name="file"; filename="example.xml" 
Content-Type: text/xml 

<hello>World!</hello> 

------------------------------ed0cb8f98262-- 

當我使用xdmp:get-request-field('file')得到TE值,它是 返回作爲包含一個文本節點的文檔節點。如果我將 text/plain更改爲application/octet-stream,則該值爲二進制 節點。

我本來料想到一個元素的文檔節點hello。該 下面的查詢重新產生此問題(訪問和outputing幾個 鍵值,要仔細檢查我的環境):

xquery version "1.0-ml"; 

import module namespace admin = "http://marklogic.com/xdmp/admin" 
    at "/MarkLogic/admin.xqy"; 

declare namespace xdmp = "http://marklogic.com/xdmp"; 
declare namespace mt = "http://marklogic.com/xdmp/mimetypes"; 

declare function local:type-from-filename($name as xs:string) as xs:string* 
{ 
    let $ext := fn:tokenize($name, '\.')[fn:last()] 
    let $types := admin:mimetypes-get(admin:get-configuration()) 
    return 
     $types[mt:extensions/data() = $ext]/mt:name 
}; 

<fields version="{ xdmp:version() }"> 
{ 
    for $name  in xdmp:get-request-field-names() 
    let $value := xdmp:get-request-field($name) 
    let $filename := xdmp:get-request-field-filename($name) 
    return 
     <field> 
     <name>{ $name }</name> 
     <is-text>{ $value/node() instance of text() }</is-text> 
     <is-binary>{ $value/node() instance of binary() }</is-binary> 
     <filename type="{ local:type-from-filename($filename) }">{ $filename }</filename> 
     <content-type>{ xdmp:get-request-field-content-type($name) }</content-type> 
     { 
      if ($value instance of binary()) then 
       <value>...binary...</value> 
      else 
       <value>{ $value }</value> 
     } 
     </field> 
} 
</fields> 

當與下面的curl命令調用(只是把上面的查詢 在HTTP應用程序服務器,並適應用戶名,密碼,並在下面端點 ):

curl -u user:pwd --digest \ 
    -F "[email protected]/example.xml;type=text/xml" \ 
    http://localhost:8010/test/tools/fields 

它返回下列信息:

<fields version="8.0-4"> 
    <field> 
     <name>file</name> 
     <is-text>true</is-text> 
     <is-binary>false</is-binary> 
     <filename type="application/xml">example.xml</filename> 
     <content-type>text/xml</content-type> 
     <value>&lt;hello&gt;World!&lt;/hello&gt; </value> 
    </field> 
</fields> 

當與下面的curl命令調用(注意不同類型 =):

curl -u user:pwd --digest \ 
    -F "[email protected]/example.xml;type=application/octet-stream" \ 
    http://localhost:8010/test/tools/fields 

它返回下列信息:

<fields version="8.0-4"> 
    <field> 
     <name>file</name> 
     <is-text>false</is-text> 
     <is-binary>false</is-binary> 
     <filename type="application/xml">example.xml</filename> 
     <content-type>application/octet-stream</content-type> 
     <value>...binary...</value> 
    </field> 
</fields> 

我錯過了什麼?我不應該得到一個XML文檔節點嗎?

也發佈在MarkLogic dev mailing list上的問題。

回答

0

對XML的文本表示使用xdmp:unquote()將其轉換爲文檔節點。

+0

嗯,當然,但是,啊哈,你知道,這聽起來像是一個缺陷,我(我是否迴歸,甚至?)我保證我總是收到它作爲文本?還是作爲二進制?要麼...? –

+0

不確定。我一直使用xdmp:unquote來達到這個目的。 –

+0

那麼..函數簽名說它返回item()*。沒有任何關於這一點的信息表明它會爲你分析任何領域的內容。唯一提到的就是關於二進制。 JSON,XML - 我們總是必須自己處理這些。如果你能證明它曾經以另一種方式工作,那將是一個迴歸問題或錯誤。只是不按照人們直覺上預期的那樣工作,並且不是缺陷或迴歸的跡象。有沒有ML版本,你注意到這個工作方式不同? –