NAMESPACE

来源:互联网 发布:js判断滚动条到底部 编辑:程序博客网 时间:2024/05/14 17:35

 

一个比较完备的schema定义需要一些ns
 <xs:schema xmlns="http://www.domain.com"
 xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
 attributeFormDefault="unqualified" targetNamespace="http://www.domain.com">
 然后在使用这个schema的xml文件中
 <ele1 xmlns="http://www.domain.com"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.domain.com/a.xsd">

 我的问题是:
 1、在schema定义中xmlns(默认的ns)和targetnamespace有何区别
 2、xml文档中的xmlns和schemaLocation有没有一些要求,比如location的a.xsd前的url要
 和xmlns的一致
 3、xml文档中定义了一个xsi的名称空间,这个有什么用途呀
 4、xml文档中的xmlns是不是要和schema里面的xmlns或者targetnamespace 保持一致

答:

1。默认ns跟targetnamespace完全是不同的东西。看下面第4点中关于targetnamespace的解释

2。关于schemaLocation,可以看http://bbs.w3china.org/dispbbs.asp?BoardID=23&ID=27215&ReplyID=22178&skin=1

另外:schemaLocation不必与xmlns的一致,这完全是两把事。

3。关于xmlns:xsi,请看
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 这句是什么意思?一定要引用这个URL吗?为什么?在实际解析的时候会不会访问这个地址?我换成别的字符串会出错的(在xmlsyp2005中)--------这是另一个命名空间,该命名空间是专门为只在实例文档中使用的属性而保留的。因为schemaLocation是在这个命名空间中的,所以要引用它;
另外我再补充一下:XSI = XML Schema Instance。

4。关于targetnamespace  和 elementFormDefault,请看:
http://bbs.w3china.org/dispbbs.asp?BoardID=23&replyID=19004&id=25672&star=1&skin=0

 

 


原创粉丝点击