XML 中的 schemaLocation 属性究竟是什么意思?
在 XML 实例文档中有时会发现有 schemaLocation 属性。很多人对此非常疑惑,搞不清这个属性究竟是什么意思,究竟该如何使用。
schemaLocation 属性用来引用(schema)模式文档,解析器可以在需要的情况下使用这个文档对 XML 实例文档进行校验。它的值(URI)是成对出现的,第一个值表示命名空间,第二个值则表示描述该命名空间的模式文档的具体位置,两个值之间以空格分隔。当然,在必要情况下,可以为 schemaLocation 属性指派多个这样的值对。
<p:Person
xmlns:p="http://contoso.com/People"
xmlns:v="http://contoso.com /Vehicles"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://contoso.com/People
http://contoso.com/schemas/people.xsd
http://contoso.com/schemas/Vehicles
http://contoso.com/schemas/vehicles.xsd
http://contoso.com/schemas/People
http://contoso.com/schemas/people.xsd">
<name>John</name>
<age>28</age>
<height>59</height>
<v:Vehicle>
<color>Red</color>
<wheels>4</wheels>
<seats>2</seats>
</v:Vehicle>
</p:Person>
如果为没有目标命名空间的模式文档指定位置,需用 noNamespaceSchemaLocation 属性.
By javafuns on July 23, 2009 at 13:43 ·
Views: 590 · Permalink
Categorized in: SOA · Tagged with: schema, XML
Categorized in: SOA · Tagged with: schema, XML


(