xmlns与targetNamespace

来源:互联网 发布:宁波淘宝摄影 编辑:程序博客网 时间:2024/05/09 15:20
xmlns与targetNamespace
http://blog.sina.com.cn/weatry
在使用XML Schema生成XML文件时,我们常常会在一个元素中看到xmlns和targetNamespace这两个属性,它们可以在任何一个XML元素上使用,它们究竟是什么含义呢?
1、xmlns使用方法
xmlns的使用格式是xmlns:namespace-prefix="namespace"
xmlns可以使用在任何元素上,表明该元素及其子元素,可以通过相应的前缀名引用定义在名字空间内的元素,可以引入多个名字空间。
比如:
<wsdl:definitions
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
</wsdl:definitions>
上述代表的含义是在definitions元素下,可以通过xsd前缀名和wsdl前缀分别引用名字空间"http://www.w3.org/2001/XMLSchema"和"http://schemas.xmlsoap.org/wsdl/"中定义的元素。
2、targetNamespace
由于在XML中并不一定都只是引用一个名字空间中的元素,有时也可能是要向一个名字空间中加入新的元素,那么应该如何向一个名字空间中加入元素呢?这时就要使用到targetNamespace。
targetNamespace也可以用在任何元素上,它代表在这个元素及其子元素下定义的任何元素、数据类型等都会被定义在指定的名字空间上。例如:
<wsdl:definitions
       targetNamespace="http://com.liuxiang.xfireDemo/HelloService"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    <wsdl:message name="xx">.....</wsdl:message>

</wsdl:definitions>


http://huangyunbin.iteye.com/blog/1172494


原创粉丝点击