【发布时间】:2015-11-26 20:06:28
【问题描述】:
我的表格有问题,我可以缩小到 下列的。它是一个多部分/表单数据类型的 POST,发送一个文件 部分:
------------------------------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。这
以下查询重现了问题(访问和输出一些
键值,仔细检查我的环境):
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 "file=@.../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><hello>World!</hello> </value>
</field>
</fields>
当使用以下 CURL 命令调用时(注意不同的 类型=):
curl -u user:pwd --digest \
-F "file=@.../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 上。
【问题讨论】:
标签: marklogic