XML规范化词典排序



这里有XML规范化的官方测试用例:规范XML 2.0 的测试用例

其中一个看起来像这样:

<!DOCTYPE doc [<!ATTLIST e9 attr CDATA "default">]>
<doc>
   <e1   />
   <e2   ></e2>
   <e3   name = "elem3"   id="elem3"   />
   <e4   name="elem4"   id="elem4"   ></e4>
   <e5 a:attr="out" b:attr="sorted" attr2="all" attr="I'm"
      xmlns:b="http://www.ietf.org"
      xmlns:a="http://www.w3.org"
      xmlns="http://example.org"/>
   <e6 xmlns="" xmlns:a="http://www.w3.org">
      <e7 xmlns="http://www.ietf.org">
         <e8 xmlns="" xmlns:a="http://www.w3.org">
            <e9 xmlns="" xmlns:a="http://www.ietf.org"/>
         </e8>
      </e7>
   </e6>
</doc> 

给定的规范化形式是

<doc>
   <e1></e1>
   <e2></e2>
   <e3 id="elem3" name="elem3"></e3>
   <e4 id="elem4" name="elem4"></e4>
   <e5 xmlns="http://example.org" xmlns:a="http://www.w3.org" xmlns:b="http://www.ietf.org" attr="I'm" attr2="all" b:attr="sorted" a:attr="out"></e5>
   <e6>
      <e7 xmlns="http://www.ietf.org">
         <e8 xmlns="">
            <e9 attr="default"></e9>
         </e8>
      </e7>
   </e6>
</doc>

我想知道为什么在排序输出中b:attr="sorted"a:attr="out"之前。。。如果有人能为我澄清这一点,我将不胜感激。

不要看名称空间前缀;查看命名空间URI。

虽然ab之前,但iw:之前

  xmlns:b="http://www.ietf.org"
  xmlns:a="http://www.w3.org"

因此,b:attr="sorted"在规范上先于a:attr="out"

第2.3节:对此进行了解释

注意:在e5中,b:attr位于a:attr之前,因为主键是命名空间URI,而不是命名空间前缀

最新更新