XML规范化的字典序
问题描述:
有官方测试用例XML规范,可以在这里找到:Test cases for Canonical XML 2.0XML规范化的字典序
其中之一是这样的:
<!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"
排序输出...我真的很感谢,如果有人可以clar如果这对我来说。
答
不要看名称空间前缀;看看命名空间的URI。
虽然a
自带b
之前,i
来w
前:
xmlns:b="http://www.ietf.org"
xmlns:a="http://www.w3.org"
因此b:attr="sorted"
来a:attr="out"
标准地之前。
这在section 2.3解释说:
注意:在
e5
,b:attr
先a:attr
因为主键是命名空间URI不是命名空间前缀