MarkLogic。在属性中加载带有重音字符的文档会生成无效的UTF-8转义序列错误

时间:2018-03-09 15:19:22

标签: utf-8 marklogic marklogic-8

我有一个UTF-8编码的xml文档,没有BOM并在元素文本中使用命名实体。我使用Powershell来获取为数字实体命名的文件和交换(因为我不总是可以访问DTD或XSD文件)并将修改后的xml发布到REST端点(它使用xdmp:document-insert)。

对于那些在属性值中带有重音字符的文档,我得到"无效的UTF-8转义序列"在日志文件中报告。下面的Xml片段......

... in Brazil (<xref ref-type="bibr" rid="i0892-1016-51-1-72-BrazilMinistériodoMeioAmbienteMMAInstitutoChicoMendesdeConservaçãodaBiodiversidadeICMBio1">Brazil Minist&eacute;rio do Meio Ambiente, Instituto Chico Mendes de Conserva&ccedil;&atilde;o da Biodiversidade 2014</xref>). This species builds....

除了使用Powershell将这些字符交换到它们的数字实体形式之外,是否有任何xquery代码来处理这个或MarkLogic中的设置?此时的角色是西欧,并且索引中不使用属性。

MarkLogic 8.0-6.7 Windows 10 Powershell 5.1

加成 周末我环顾四周。在MarkLogic方面,我在&#39; try-catch&#39;之外提取了xdmp:get-request-body的副本。并且错误证实了你(Mads)的怀疑。 我查看了Powershell,它将文本内容导入为UTF8(Encode a string in UTF-8),但显然是将文本作为默认字符集(1252?)发布。

function getBody ($FilePath)
{
$fileContentBinary = [System.IO.File]::ReadAllBytes($FilePath)
$enc               = [System.Text.Encoding]::GetEncoding("UTF-8")
$encodedContent    =  $enc.GetString($fileContentBinary)
$encodedContent    = elementReplace($encodedContent) 
return $encodedContent 
}

function sendXml ($MLHost, $LocalFilePath, $SUPPLIER_REF, $credentials, $xsltTRANSFORMLABEL)
{
 Add-content $logfile -value ('Posting file '  + $LocalFilePath + ' to ' + $MLHost + ' for supplier ' + $SUPPLIER_REF)
 $filename        =  (Split-Path $LocalFilePath -leaf)
 $EndpointAddress = 'http://{0}:######/nps3/article/upload/?supplier={1}&filename={2}&transform={3}' -f $MLHost, $SUPPLIER_REF, $filename, $xsltTRANSFORMLABEL ;
 $boundary        =  [System.Guid]::NewGuid().ToString()
 $bodyText        =  makeBody $LocalFilePath
 $contentType     = 'multipart/form-data; boundary={0}' -f $boundary;
 try   { 
       Invoke-RestMethod -uri $EndpointAddress -Method PUT -ContentType $contentType -body $bodyText -Credential $credentials

       #all ok so delete file
       if (Test-Path $LocalFilePath) {
       Remove-Item $LocalFilePath
        }
        }
  catch {
        Add-content $logfile -value ('A problem was encountered inserting "' + (Split-Path $LocalFilePath -leaf) + ' --> ' + $_.Exception.Message )
    }}

我补充说     $ OutputEncoding = New-Object -typename System.Text.UTF8Encoding 到Powershell脚本的顶部(假设它将UTF8设置为会话的默认字符集??)并添加了一个charset参数 到$ contentType语句

$contentType = 'multipart/form-data; boundary={0} ; charset=utf-8' -f $boundary;

这些更改似乎已纠正此问题。是&#39; $ OutputEncoding&#39;如果在代码顶部添加会话,则将会话的整个编码更改为UTF8?

0 个答案:

没有答案