我有一个表格的问题,我可以缩小到以下范围。这是一个多部分/表单数据类型的帖子,发送一个文件部分:
------------------------------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命令调用时(请注意不同的type=):
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上。
发布于 2015-11-27 20:49:02
在XML的文本表示形式上使用xdmp:unquote()将其转换为文档节点。
https://stackoverflow.com/questions/33946268
复制相似问题