xml 命名空间绑定的范围
示例
命名空间绑定(特殊xmlns或xmlns:...属性)在包围元素(包括此元素)的所有后代的范围内。
<?xml version="1.0"?>
<root>
<my:element xmlns:my="http://www.example.com/ns1">
<!-- here, the prefix my is bound to http://www.example.com/ns1 -->
</my:element>
<my:element xmlns:my="http://www.example.com/ns2">
<!-- here, the prefix my is bound to http://www.example.com/ns2 -->
</my:element>
</root>可以在嵌套元素中重写绑定(尽管这会影响可读性):
<?xml version="1.0"?>
<my:element xmlns:my="http://www.example.com/ns1">
<!-- here, the prefix my is bound to http://www.example.com/ns1 -->
<my:first-child-element/>
<my:child-element xmlns:my="http://www.example.com/ns2">
<!-- here, the prefix my is bound to http://www.example.com/ns2,
including for the element my:child-element -->
</my:child-element>
<!-- here, the prefix my is bound to http://www.example.com/ns1 -->
<my:last-child-element/>
</my:element>在根元素中声明所有名称空间绑定是很常见的,这提高了可读性。
<?xml version="1.0"?>
<root
xmlns="http://www.example.com/default-namespace"
xmlns:ns1="http://www.example.com/ns1"
xmlns:ns2="http://www.example.com/ns2">
<ns1:element>
<ns2:other-element/>
</ns1:element>
</root>
热门推荐
10 朋友新年祝福语大全 简短
11 新年祝福语简短大方兔年
12 搬新家礼物祝福语简短
13 同学见面花束祝福语简短
14 五一假期祝福语幽默简短
15 离职欢送敬酒祝福语简短
16 对学弟的祝福语简短
17 考老师辞职祝福语简短
18 祝福语驱散霉运的话简短