使用不带 url 或 uri 的名称空间。我很困惑
use namespace without url or uri .I'm confused
我刚开始使用 XML,我正在学习第一个概念。我对名称空间的使用感到困惑。我准备了两个简单的文件:一个 xml-schema 和 XML document 。如果我犯了错误,请帮助理解错误,并尝试解释如何在我的电脑上而不是在网站上使用模式文件。我问这个是因为我找到的所有示例都使用 url 之类的名称空间或位置 file.xml 。
谢谢。
P.S。对不起我的英语不好
这是cdSchema.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="CD"
xmlns="CD">
<xs:element name="artist" type="xs:string"/>
<xs:element name="length" type="xs:string"/>
<xs:element name="title" type="xs:string"/>
<xs:element name="year" type="xs:string"/>
<xs:element name="song">
<xs:complexType>
<xs:sequence>
<xs:element ref="artist"/>
<xs:element ref="length"/>
<xs:element ref="title"/>
<xs:element ref="year"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
这是compactDisc.xml
<?xml version="1.0" encoding="UTF-8"?>
<CD xmlns="CD"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="CD cdSchema.xsd">
<song>
<artist>Santana</artist>
<title>African Song</title>
<length>4:42</length>
<year>1993</year>
</song>
<song>
<artist>Santana</artist>
<title>Corazon Espinado</title>
<length>4:36</length>
<year>1996</year>
</song>
</CD>
谢谢大家
XML 规范强烈鼓励使用 URI 作为命名空间名称,最好在您拥有的域中使用 URI,例如 http://www.my-domain.com/ns/CD
(替换您的 CD
).这是为了让您高度相信您的命名空间是独一无二的。您实际上不必在此地址拥有网络服务器。人们对命名空间使用 "http" 方案确实有点不幸,使用 namespace://www.my-domain.com/CD
可能会更好,以明确我们不是在谈论使用 HTTP 访问的资源;但出于某种原因,使用 "http:" 的惯例流行起来。
我刚开始使用 XML,我正在学习第一个概念。我对名称空间的使用感到困惑。我准备了两个简单的文件:一个 xml-schema 和 XML document 。如果我犯了错误,请帮助理解错误,并尝试解释如何在我的电脑上而不是在网站上使用模式文件。我问这个是因为我找到的所有示例都使用 url 之类的名称空间或位置 file.xml 。 谢谢。
P.S。对不起我的英语不好
这是cdSchema.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="CD"
xmlns="CD">
<xs:element name="artist" type="xs:string"/>
<xs:element name="length" type="xs:string"/>
<xs:element name="title" type="xs:string"/>
<xs:element name="year" type="xs:string"/>
<xs:element name="song">
<xs:complexType>
<xs:sequence>
<xs:element ref="artist"/>
<xs:element ref="length"/>
<xs:element ref="title"/>
<xs:element ref="year"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
这是compactDisc.xml
<?xml version="1.0" encoding="UTF-8"?>
<CD xmlns="CD"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="CD cdSchema.xsd">
<song>
<artist>Santana</artist>
<title>African Song</title>
<length>4:42</length>
<year>1993</year>
</song>
<song>
<artist>Santana</artist>
<title>Corazon Espinado</title>
<length>4:36</length>
<year>1996</year>
</song>
</CD>
谢谢大家
XML 规范强烈鼓励使用 URI 作为命名空间名称,最好在您拥有的域中使用 URI,例如 http://www.my-domain.com/ns/CD
(替换您的 CD
).这是为了让您高度相信您的命名空间是独一无二的。您实际上不必在此地址拥有网络服务器。人们对命名空间使用 "http" 方案确实有点不幸,使用 namespace://www.my-domain.com/CD
可能会更好,以明确我们不是在谈论使用 HTTP 访问的资源;但出于某种原因,使用 "http:" 的惯例流行起来。