Rac*_*pal 1 xquery tidy htmltidy marklogic marklogic-8
我的内容在我的旧数据库中既不是有效的HTML也不是XML.考虑到这个事实,很难清理遗留问题,我想在MarkLogic中使用xdmp:tidy来整理它.我目前正在使用ML-8.
<sub>
<p>
<???†?>
</p>
</sub>
Run Code Online (Sandbox Code Playgroud)
我正在通过某种方式将此内容传递给整洁的功能:
declare variable $xml as node() :=
<content>
<![CDATA[<p><???†?></p>]]>
</content>;
xdmp:tidy(xdmp:quote($xml//text()),
<options xmlns="xdmp:tidy">
<assume-xml-procins>yes</assume-xml-procins>
<quiet>yes</quiet>
<tidy-mark>no</tidy-mark>
<enclose-text>yes</enclose-text>
<indent>yes</indent>
</options>)
Run Code Online (Sandbox Code Playgroud)
结果它返回:
<p>
<? ?†?>
</p>
Run Code Online (Sandbox Code Playgroud)
现在这个结果不是有效的xml格式(我通过XML验证器检查过),因为当我尝试将这个XML插入MarkLogic时,它会抛出一个错误,说'MALFORMED BODY | 无效的处理指令名称'.
我对PI进行了一些调查,但没有太多运气.我本可以尝试在没有PI的情况下保存内容,但这也不是一个有效的PI.
这是因为您认为PI实际上不是PI.来自W3C:
2.6处理说明
[定义:处理指令(PI)允许文档包含应用程序的说明.]
处理说明
[16] PI :: =''Char*)))?'?>'
[17] PITarget :: =名字 - (('X'|'x')('M'|'m')('L'|'l'))
那么PI名称不能以?开头?如你的样本??†您可能希望在将内容传递给整洁之前清理内容.如下所示:
declare variable $xml as node() :=
<content><![CDATA[<p>Hello <???†?>world</p>]]></content>;
declare function local:copy($input as item()*) as item()* {
for $node in $input
return
typeswitch($node)
case text()
return fn:replace($node,"<\?[^>]+\?>","")
case element()
return
element {name($node)} {
(: output each attribute in this element :)
for $att in $node/@*
return
attribute {name($att)} {$att}
,
(: output all the sub-elements of this element recursively :)
for $child in $node
return local:copy($child/node())
}
(: otherwise pass it through. Used for text(), comments, and PIs :)
default return $node
};
xdmp:tidy(local:copy($xml),
<options xmlns="xdmp:tidy">
<assume-xml-procins>no</assume-xml-procins>
<quiet>yes</quiet>
<tidy-mark>no</tidy-mark>
<enclose-text>yes</enclose-text>
<indent>yes</indent>
</options>)
Run Code Online (Sandbox Code Playgroud)
这样做可以摆脱所有PI(真实和假的PI)
问候,
彼得
| 归档时间: |
|
| 查看次数: |
167 次 |
| 最近记录: |