上传 MarkLogic 时强制执行 XML contentType
Enforcing XML contentType while uploading MarkLogic
虽然上传文件带有明确的 .xml 通过 http 服务器扩展。 MarkLogic 将其作为 .txt 文件保存在我的本地数据库中。
这意味着我不能运行我的查询反对它。
上传者:
declare function local:uploadFile()
{
let $filename := xdmp:get-request-field-filename("upload")
let $file := xdmp:get-request-field("upload")
let $collection := "semansysdocs"
return
xdmp:document-insert(
$filename,
$file,
xdmp:default-permissions(),
(xdmp:default-collections(), $collection)
)
};
示例文档(文件名:Prod223_1982_03975172_20170430.xml):
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="http://www.companieshouse.gov.uk/ef/xbrl/uk/fr/gaap/ae/2009-06-21/stylesheet/CH-AE-dormant-stylesheet.xsl"?>
<xbrl
xmlns="http://www.xbrl.org/2003/instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ae="http://www.companieshouse.gov.uk/ef/xbrl/uk/fr/gaap/ae/2009-06-21"
xmlns:gc="http://www.xbrl.org/uk/fr/gcd/2004-12-01"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:iso4217="http://www.xbrl.org/2003/iso4217"
xmlns:link="http://www.xbrl.org/2003/linkbase"
xmlns:pt="http://www.xbrl.org/uk/fr/gaap/pt/2004-12-01"
xmlns:xbrli="http://www.xbrl.org/2003/instance"
xmlns:xlink="http://www.w3.org/1999/xlink">
<link:schemaRef xlink:arcrole="http://www.w3.org/1999/xlink/properties/linkbase"
xlink:href="http://www.companieshouse.gov.uk/ef/xbrl/uk/fr/gaap/ae/2009-06-21/uk-gaap-ae-2009-06-21.xsd"
xlink:type="simple"/>
<ae:CompanyDormant contextRef="y2017">true</ae:CompanyDormant>
<gc:EntityNames>
<gc:EntityCurrentLegalName contextRef="y2017">HUNTS GROUP PLC</gc:EntityCurrentLegalName>
</gc:EntityNames>
<ae:CompanyIdentifyingNumbers>
<ae:CompaniesHouseRegisteredNumber contextRef="y2017">03975172</ae:CompaniesHouseRegisteredNumber>
</ae:CompanyIdentifyingNumbers>
<gc:StatementDatesPeriodsCovered>
<gc:BalanceSheetDate contextRef="e2017">2017-04-30</gc:BalanceSheetDate>
</gc:StatementDatesPeriodsCovered>
<pt:ShareholderFunds precision="6" contextRef="e2017" unitRef="GBP">12500</pt:ShareholderFunds>
<pt:ShareholderFunds precision="6" contextRef="e2016" unitRef="GBP">12500</pt:ShareholderFunds>
<pt:NetAssetsLiabilitiesIncludingPensionAssetLiability precision="5" contextRef="e2017" unitRef="GBP">12500</pt:NetAssetsLiabilitiesIncludingPensionAssetLiability>
<pt:NetAssetsLiabilitiesIncludingPensionAssetLiability precision="5" contextRef="e2016" unitRef="GBP">12500</pt:NetAssetsLiabilitiesIncludingPensionAssetLiability>
<pt:CashBankInHand precision="5" contextRef="e2017" unitRef="GBP">12500</pt:CashBankInHand>
<pt:CashBankInHand precision="5" contextRef="e2016" unitRef="GBP">12500</pt:CashBankInHand>
<pt:EquityAuthorisedDetails>
<pt:TypeOrdinaryShare contextRef="y2017">Ordinary</pt:TypeOrdinaryShare>
<pt:NumberOrdinarySharesAuthorised precision="INF" contextRef="e2017" unitRef="shares">50000</pt:NumberOrdinarySharesAuthorised>
<pt:ParValueOrdinaryShare precision="INF" contextRef="y2017" unitRef="GBP">1</pt:ParValueOrdinaryShare>
</pt:EquityAuthorisedDetails>
<pt:DetailsOrdinarySharesAllotted>
<pt:TypeOrdinaryShare contextRef="y2017">Ordinary</pt:TypeOrdinaryShare>
<pt:ParValueOrdinaryShare precision="INF" contextRef="y2017" unitRef="GBP">1</pt:ParValueOrdinaryShare>
<pt:ValueOrdinarySharesAllotted precision="5" contextRef="e2017" unitRef="GBP">12500</pt:ValueOrdinarySharesAllotted>
<pt:ValueOrdinarySharesAllotted precision="5" contextRef="e2016" unitRef="GBP">12500</pt:ValueOrdinarySharesAllotted>
<pt:NumberOrdinarySharesAllotted precision="INF" contextRef="e2017" unitRef="shares">12500</pt:NumberOrdinarySharesAllotted>
</pt:DetailsOrdinarySharesAllotted>
<pt:DateApproval contextRef="e2017">2017-10-13</pt:DateApproval>
<pt:ApprovalDetails>
<pt:NameApprovingDirector contextRef="y2017">Mr. David Charles Hunt</pt:NameApprovingDirector>
</pt:ApprovalDetails>
<ae:CompanyEntitledToExemptionUnderSection480CompaniesAct2006 contextRef="y2017">true</ae:CompanyEntitledToExemptionUnderSection480CompaniesAct2006>
<ae:MembersHaveNotRequiredCompanyToObtainAnAudit contextRef="y2017">true</ae:MembersHaveNotRequiredCompanyToObtainAnAudit>
<ae:DirectorsAcknowledgeTheirResponsibilitiesUnderCompaniesAct contextRef="y2017">true</ae:DirectorsAcknowledgeTheirResponsibilitiesUnderCompaniesAct>
<ae:AccountsAreInAccordanceWithSpecialProvisionsCompaniesActRelatingToSmallCompanies contextRef="y2017">true</ae:AccountsAreInAccordanceWithSpecialProvisionsCompaniesActRelatingToSmallCompanies>
<unit id="shares">
<measure>xbrli:shares</measure>
</unit>
<unit id="GBP">
<measure>iso4217:GBP</measure>
</unit>
<unit id="pure">
<measure>xbrli:pure</measure>
</unit>
<context id="y2017">
<entity>
<identifier scheme="/results">HUNTS GROUP PLC</identifier>
</entity>
<period>
<startDate>2016-05-01</startDate>
<endDate>2017-04-30</endDate>
</period>
</context>
<context id="y2016">
<entity>
<identifier scheme="/results">HUNTS GROUP PLC</identifier>
</entity>
<period>
<startDate>2015-05-01</startDate>
<endDate>2016-04-30</endDate>
</period>
</context>
<context id="s2016">
<entity>
<identifier scheme="/results">HUNTS GROUP PLC</identifier>
</entity>
<period>
<instant>2015-04-30</instant>
</period>
</context>
<context id="e2016">
<entity>
<identifier scheme="/results">HUNTS GROUP PLC</identifier>
</entity>
<period>
<instant>2016-04-30</instant>
</period>
</context>
<context id="s2017">
<entity>
<identifier scheme="/results">HUNTS GROUP PLC</identifier>
</entity>
<period>
<instant>2016-04-30</instant>
</period>
</context>
<context id="e2017">
<entity>
<identifier scheme="/results">HUNTS GROUP PLC</identifier>
</entity>
<period>
<instant>2017-04-30</instant>
</period>
</context>
<ae:CompaniesHouseDocumentAuthentication contextRef="y2017"></ae:CompaniesHouseDocumentAuthentication>
<ae:DateAccountsReceived contextRef="e2017">2017-10-16</ae:DateAccountsReceived>
</xbrl>
如您所见,这是一个XBRL文档吗,大致是XML+。我无法在 xdmp:document-insert()
中指定 contentType,你们知道如何强制执行 XML contentType 吗?
在插入之前,您需要将其解析回 XML(我猜这是通过网络传输的文本)。这是通过 xdmp:unquote()
完成的
....
let $file := xdmp:unquote(xdmp:get-request-field("upload"))
....
请注意以上是简化的。您可能需要根据需要设置其他选项 - 请参阅文档了解详细信息。
与此不同 - 你声明文档是 .txt ..我假设你的意思是它是一个文本节点。 MarkLogic 不会将任何 .txt 添加到 URI 中的文件名。如果您看到了,那么这就是请求字段中发送的内容。
当使用下面的代码时,一些已知的内容类型/文件扩展名将按您的预期被提取:
let $file := xdmp:get-request-field("upload")
let $filename := xdmp:get-request-field-filename("upload")
let $contenttype := xdmp:get-request-field-content-type("upload")
let $extension := fn:replace($filename, '.*\.', '')
let $insert := switch ($contenttype)
case "text/xml"
case "text/xhtml"
case "text/csv"
case "text/plain"
case "application/json"
return xdmp:document-insert($filename,xdmp:unquote($file))
case "application/octet-stream"
return switch ($extension)
case "gpx"
return xdmp:document-insert($filename,xdmp:unquote(xdmp:quote(binary{xs:hexBinary($file)})))
default
return xdmp:document-insert($filename,$file)
default
return xdmp:document-insert($filename,$file)
return fn:concat("file '",$filename,"' uploaded, contenttype: ",$contenttype," extension: ",$extension)
Result of uploading various file formats
虽然上传文件带有明确的 .xml 通过 http 服务器扩展。 MarkLogic 将其作为 .txt 文件保存在我的本地数据库中。
这意味着我不能运行我的查询反对它。
上传者:
declare function local:uploadFile()
{
let $filename := xdmp:get-request-field-filename("upload")
let $file := xdmp:get-request-field("upload")
let $collection := "semansysdocs"
return
xdmp:document-insert(
$filename,
$file,
xdmp:default-permissions(),
(xdmp:default-collections(), $collection)
)
};
示例文档(文件名:Prod223_1982_03975172_20170430.xml):
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="http://www.companieshouse.gov.uk/ef/xbrl/uk/fr/gaap/ae/2009-06-21/stylesheet/CH-AE-dormant-stylesheet.xsl"?>
<xbrl
xmlns="http://www.xbrl.org/2003/instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ae="http://www.companieshouse.gov.uk/ef/xbrl/uk/fr/gaap/ae/2009-06-21"
xmlns:gc="http://www.xbrl.org/uk/fr/gcd/2004-12-01"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:iso4217="http://www.xbrl.org/2003/iso4217"
xmlns:link="http://www.xbrl.org/2003/linkbase"
xmlns:pt="http://www.xbrl.org/uk/fr/gaap/pt/2004-12-01"
xmlns:xbrli="http://www.xbrl.org/2003/instance"
xmlns:xlink="http://www.w3.org/1999/xlink">
<link:schemaRef xlink:arcrole="http://www.w3.org/1999/xlink/properties/linkbase"
xlink:href="http://www.companieshouse.gov.uk/ef/xbrl/uk/fr/gaap/ae/2009-06-21/uk-gaap-ae-2009-06-21.xsd"
xlink:type="simple"/>
<ae:CompanyDormant contextRef="y2017">true</ae:CompanyDormant>
<gc:EntityNames>
<gc:EntityCurrentLegalName contextRef="y2017">HUNTS GROUP PLC</gc:EntityCurrentLegalName>
</gc:EntityNames>
<ae:CompanyIdentifyingNumbers>
<ae:CompaniesHouseRegisteredNumber contextRef="y2017">03975172</ae:CompaniesHouseRegisteredNumber>
</ae:CompanyIdentifyingNumbers>
<gc:StatementDatesPeriodsCovered>
<gc:BalanceSheetDate contextRef="e2017">2017-04-30</gc:BalanceSheetDate>
</gc:StatementDatesPeriodsCovered>
<pt:ShareholderFunds precision="6" contextRef="e2017" unitRef="GBP">12500</pt:ShareholderFunds>
<pt:ShareholderFunds precision="6" contextRef="e2016" unitRef="GBP">12500</pt:ShareholderFunds>
<pt:NetAssetsLiabilitiesIncludingPensionAssetLiability precision="5" contextRef="e2017" unitRef="GBP">12500</pt:NetAssetsLiabilitiesIncludingPensionAssetLiability>
<pt:NetAssetsLiabilitiesIncludingPensionAssetLiability precision="5" contextRef="e2016" unitRef="GBP">12500</pt:NetAssetsLiabilitiesIncludingPensionAssetLiability>
<pt:CashBankInHand precision="5" contextRef="e2017" unitRef="GBP">12500</pt:CashBankInHand>
<pt:CashBankInHand precision="5" contextRef="e2016" unitRef="GBP">12500</pt:CashBankInHand>
<pt:EquityAuthorisedDetails>
<pt:TypeOrdinaryShare contextRef="y2017">Ordinary</pt:TypeOrdinaryShare>
<pt:NumberOrdinarySharesAuthorised precision="INF" contextRef="e2017" unitRef="shares">50000</pt:NumberOrdinarySharesAuthorised>
<pt:ParValueOrdinaryShare precision="INF" contextRef="y2017" unitRef="GBP">1</pt:ParValueOrdinaryShare>
</pt:EquityAuthorisedDetails>
<pt:DetailsOrdinarySharesAllotted>
<pt:TypeOrdinaryShare contextRef="y2017">Ordinary</pt:TypeOrdinaryShare>
<pt:ParValueOrdinaryShare precision="INF" contextRef="y2017" unitRef="GBP">1</pt:ParValueOrdinaryShare>
<pt:ValueOrdinarySharesAllotted precision="5" contextRef="e2017" unitRef="GBP">12500</pt:ValueOrdinarySharesAllotted>
<pt:ValueOrdinarySharesAllotted precision="5" contextRef="e2016" unitRef="GBP">12500</pt:ValueOrdinarySharesAllotted>
<pt:NumberOrdinarySharesAllotted precision="INF" contextRef="e2017" unitRef="shares">12500</pt:NumberOrdinarySharesAllotted>
</pt:DetailsOrdinarySharesAllotted>
<pt:DateApproval contextRef="e2017">2017-10-13</pt:DateApproval>
<pt:ApprovalDetails>
<pt:NameApprovingDirector contextRef="y2017">Mr. David Charles Hunt</pt:NameApprovingDirector>
</pt:ApprovalDetails>
<ae:CompanyEntitledToExemptionUnderSection480CompaniesAct2006 contextRef="y2017">true</ae:CompanyEntitledToExemptionUnderSection480CompaniesAct2006>
<ae:MembersHaveNotRequiredCompanyToObtainAnAudit contextRef="y2017">true</ae:MembersHaveNotRequiredCompanyToObtainAnAudit>
<ae:DirectorsAcknowledgeTheirResponsibilitiesUnderCompaniesAct contextRef="y2017">true</ae:DirectorsAcknowledgeTheirResponsibilitiesUnderCompaniesAct>
<ae:AccountsAreInAccordanceWithSpecialProvisionsCompaniesActRelatingToSmallCompanies contextRef="y2017">true</ae:AccountsAreInAccordanceWithSpecialProvisionsCompaniesActRelatingToSmallCompanies>
<unit id="shares">
<measure>xbrli:shares</measure>
</unit>
<unit id="GBP">
<measure>iso4217:GBP</measure>
</unit>
<unit id="pure">
<measure>xbrli:pure</measure>
</unit>
<context id="y2017">
<entity>
<identifier scheme="/results">HUNTS GROUP PLC</identifier>
</entity>
<period>
<startDate>2016-05-01</startDate>
<endDate>2017-04-30</endDate>
</period>
</context>
<context id="y2016">
<entity>
<identifier scheme="/results">HUNTS GROUP PLC</identifier>
</entity>
<period>
<startDate>2015-05-01</startDate>
<endDate>2016-04-30</endDate>
</period>
</context>
<context id="s2016">
<entity>
<identifier scheme="/results">HUNTS GROUP PLC</identifier>
</entity>
<period>
<instant>2015-04-30</instant>
</period>
</context>
<context id="e2016">
<entity>
<identifier scheme="/results">HUNTS GROUP PLC</identifier>
</entity>
<period>
<instant>2016-04-30</instant>
</period>
</context>
<context id="s2017">
<entity>
<identifier scheme="/results">HUNTS GROUP PLC</identifier>
</entity>
<period>
<instant>2016-04-30</instant>
</period>
</context>
<context id="e2017">
<entity>
<identifier scheme="/results">HUNTS GROUP PLC</identifier>
</entity>
<period>
<instant>2017-04-30</instant>
</period>
</context>
<ae:CompaniesHouseDocumentAuthentication contextRef="y2017"></ae:CompaniesHouseDocumentAuthentication>
<ae:DateAccountsReceived contextRef="e2017">2017-10-16</ae:DateAccountsReceived>
</xbrl>
如您所见,这是一个XBRL文档吗,大致是XML+。我无法在 xdmp:document-insert()
中指定 contentType,你们知道如何强制执行 XML contentType 吗?
在插入之前,您需要将其解析回 XML(我猜这是通过网络传输的文本)。这是通过 xdmp:unquote()
完成的....
let $file := xdmp:unquote(xdmp:get-request-field("upload"))
....
请注意以上是简化的。您可能需要根据需要设置其他选项 - 请参阅文档了解详细信息。
与此不同 - 你声明文档是 .txt ..我假设你的意思是它是一个文本节点。 MarkLogic 不会将任何 .txt 添加到 URI 中的文件名。如果您看到了,那么这就是请求字段中发送的内容。
当使用下面的代码时,一些已知的内容类型/文件扩展名将按您的预期被提取:
let $file := xdmp:get-request-field("upload")
let $filename := xdmp:get-request-field-filename("upload")
let $contenttype := xdmp:get-request-field-content-type("upload")
let $extension := fn:replace($filename, '.*\.', '')
let $insert := switch ($contenttype)
case "text/xml"
case "text/xhtml"
case "text/csv"
case "text/plain"
case "application/json"
return xdmp:document-insert($filename,xdmp:unquote($file))
case "application/octet-stream"
return switch ($extension)
case "gpx"
return xdmp:document-insert($filename,xdmp:unquote(xdmp:quote(binary{xs:hexBinary($file)})))
default
return xdmp:document-insert($filename,$file)
default
return xdmp:document-insert($filename,$file)
return fn:concat("file '",$filename,"' uploaded, contenttype: ",$contenttype," extension: ",$extension)
Result of uploading various file formats