【问题标题】:SaxonJS emits superfulous namespace attributesSaxonJS 发出多余的命名空间属性
【发布时间】:2020-07-08 12:30:20
【问题描述】:

使用 SaxonJS 时,我能够验证它是否产生与 Saxon 相同的输出,但需要注意一点。 SaxonJS 似乎会为每个元素发出命名空间属性,即使它们不是必需的。我尝试调整exclude-result-prefixes,但没有效果。

SaxonJS 1.2.0 输出

<CastVoteRecordReport xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="NIST_V0_cast_vote_records.xsd" xsi:schemaLocation="NIST_V0_cast_vote_records.xsd NIST_V0_cast_vote_records.xsd">
    <CVR xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="NIST_V0_cast_vote_records.xsd">
        <BallotStyleId xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="NIST_V0_cast_vote_records.xsd">_01-0052-01</BallotStyleId>
        <CreatingDeviceId xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="NIST_V0_cast_vote_records.xsd">rd</CreatingDeviceId>
        <CurrentSnapshotId xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="NIST_V0_cast_vote_records.xsd">i__a_aaaaaago</CurrentSnapshotId>
        <CVRSnapshot xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="NIST_V0_cast_vote_records.xsd" ObjectId="i__a_aaaaaago">
            <CVRContest xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="NIST_V0_cast_vote_records.xsd">
                <ContestId xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="NIST_V0_cast_vote_records.xsd">_1GO</ContestId>
                <Undervotes xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="NIST_V0_cast_vote_records.xsd">1</Undervotes>
            </CVRContest>
...

Saxon-EE 版本 9.8.0.12 输出

<?xml version="1.0" encoding="UTF-8"?>
<CastVoteRecordReport xmlns="NIST_V0_cast_vote_records.xsd"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <CVR>
      <BallotStyleId>_01-0052-01</BallotStyleId>
      <CreatingDeviceId>rd</CreatingDeviceId>
      <CurrentSnapshotId>i__a_aaaaaago</CurrentSnapshotId>
      <CVRSnapshot ObjectId="i__a_aaaaaago">
         <CVRContest>
            <ContestId>_1GO</ContestId>
            <Undervotes>1</Undervotes>
         </CVRContest>
...

SaxonJS.Transform 上的回调是

var transformCallback = (fragment: DocumentFragment) => {
            // have to convert to string?
            var div = document.createElement('div');
            div.appendChild(fragment.cloneNode(true));
            // replace existing output content
            that.outputText(div.innerHTML);
}

【问题讨论】:

    标签: xml-namespaces saxon saxon-js


    【解决方案1】:

    Saxon-JS 1.2.0 没有(完整、一致的)序列化程序,所以问题出现了,您如何生成问题中显示的词法 XML 输出?

    就 XDM 数据模型而言,XML 和 XSI 命名空间确实应该在结果树中的每个元素的范围内;一个好的序列化程序将消除多余的命名空间。所以这都是关于结果树如何被序列化的问题。

    (注意,Saxon-JS 2.0 是测试的最后阶段,将有一个完整的序列化器。)

    【讨论】:

    • 我认为基本上,Saxon-JS 正在构建最接近 XSLT 规范中定义 XDM 模型的方式的 DOM 树——其中包括继承的命名空间的副本——并且它依赖于在串行器上消除冗余;但是这个序列化程序没有这样做。 Saxon-JS 2 应该改进这一点。 (如果您有兴趣对预发布版本进行 Beta 测试,请与 Saxonica 离线交谈)。
    • Saxon-JS 2.0 能改善这种情况吗?
    • 如果没有更多关于你在做什么以及你是如何产生输出的信息,真的无法判断。结果树的整个构建方式已经改变,因此情况很可能会有所不同。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-05
    • 1970-01-01
    • 2014-06-15
    • 2017-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多