简体   繁体   English

没有schemaLocation的XMLSchema和XMLSchema实例名称空间

[英]XMLSchema and XMLSchema-instance namespaces without schemaLocation

I have few questions about xml namespace, I will explain with these three pieces of code: 我对xml命名空间的问题很少,我将用这三段代码解释:

1 - Very simple XML Schema: 1 - 非常简单的XML Schema:

<?xml version="1.0" encoding="US-ASCII"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
        xmlns:tns="http://www.library.com"
        targetNamespace="http://www.library.com"
        elementFormDefault="qualified"
        attributeFormDefault="unqualified">

<element name="Book" type="tns:BookType" />

<complexType name="BookType">
  <sequence>
    <element name="Title" type="string" />
    <element name="Author" type="string" />
  </sequence>
</complexType>

</schema>

2 - XML that use the newly created xml schema: 2 - 使用新创建的xml架构的XML:

<?xml version="1.0" encoding="US-ASCII"?>
<Book xmlns:xsi="http://www.wc3.org/2001XMLSchema-instance"
            xsi:schemaLocation="http://www.library.com ex9.xsd"
            xmlns="http://www.library.com">

   <Title>Scherlock Holmes</Title>
   Author>Arthur Conan Doyle</Author>
</Book>

3 - Another fragment code without relationship from the two above: 3 - 与上述两个没有关系的另一个片段代码:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
                        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd 
                        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
    ....
    </beans>

Question are: 问题是:

  1. Why always are we declare namespaces like xmlns="http://www.w3.org/2001/XMLSchema" and xmlns:xsi="http://www.wc3.org/2001/XMLSchema-instance" but no schemaLocation for these is given? 为什么我们总是声明名称空间,如xmlns =“http://www.w3.org/2001/XMLSchema”xmlns:xsi =“http://www.wc3.org/2001/XMLSchema-instance”但没有schemaLocation为给出了这些?
  2. How an XML parser will know (for example for to validate) that xmlns="http://www.w3.org/2001/XMLSchema" define elements like <attribute> , <complexType> , <sequence> , etc? XML解析器如何知道(例如验证) xmlns =“http://www.w3.org/2001/XMLSchema”定义<attribute><complexType><sequence>等元素?
  3. Reading many posts I understood that namespaces and thus their URI, means basically nothing, they are used just for avoid name conflicting. 阅读很多帖子我理解名称空间,因此它们的URI,基本上没什么意思,它们只是用来避免名称冲突。 But I read also that if you declare xmlns="http://www.w3.org/2001/XMLSchema" namespace wrong the XML file will not valid, why? 但我还读到,如果你声明xmlns =“http://www.w3.org/2001/XMLSchema”命名空间错误,XML文件将无效,为什么?
  4. Why In the last code fragment always no schemaLocation is given for http://www.w3.org/2001/XMLSchema-instance . 为什么在最后一个代码片段中始终没有为http://www.w3.org/2001/XMLSchema-instance提供 schemaLocation
  1. Those built-in namespaces pertain to XSD components themselves. 这些内置命名空间与XSD组件本身有关。 No schemaLocation is necessary because their definition is implied by the XML Schema Recommendation. 不需要schemaLocation ,因为XML Schema Recommendation暗示了它们的定义。
  2. A conformant XML parser by definition will understand the meaning of xs:attribute , etc. 根据定义,符合条件的XML解析器将理解xs:attribute等的含义。
  3. I wouldn't say that namespaces mean nothing. 我不会说名称空间毫无意义。 Beyond being a way of differentiating otherwise identifically named components, namespaces can also be used to associate the use of components with their collective definition in another XSD. 除了作为区分其他识别命名组件的方法之外,名称空间还可用于将组件的使用与其在另一个XSD中的集合定义相关联。
  4. As stated in #1, http://www.w3.org/2001/XMLSchema-instance is a built-in namespace consisting of components whose definitions are already implied by the XML Schema Recommendation. 如#1中所述, http://www.w3.org/2001/XMLSchema-instance是一个内置命名空间,由XML Schema Recommendation暗示的组件组成。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以在父标记以及子标记中写入XMLSchema-instance? - Is it possible to write XMLSchema-instance in parent tag as well as child tag? SOAPUI SOAP模拟错误:前缀不能以XML开头:XMLSchema-instance - SOAPUI SOAP Mocking error : Prefix can't begin with XML: XMLSchema-instance 避免在.Net DataContractSerializer中使用“http://www.w3.org/2001/XMLSchema-instance”命名空间 - Avoiding using the “http://www.w3.org/2001/XMLSchema-instance” namespace with .Net DataContractSerializer 错误:属性声明的非法命名空间:http://www.w3.org/2001/XMLSchema-instance - Error: Illegal namespace for attribute declaration: http://www.w3.org/2001/XMLSchema-instance 将 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 添加到根元素 - Add xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" to the root element 从名称空间&#39;http://www.w3.org/2001/XMLSchema-instance&#39;期望元素&#39;CustomerLeads&#39; - Expecting element 'CustomerLeads' from namespace 'http://www.w3.org/2001/XMLSchema-instance' xmlns:xsi =“http://www.w3.org/2001/XMLSchema-instance”是XML中的一个特例吗? - Is xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” a special case in XML? 使用 DataContractSerializer 时删除 xmlns:i=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; - remove xmlns:i=“http://www.w3.org/2001/XMLSchema-instance” when using DataContractSerializer JAXB - 防止空属性 xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:nil=&quot;true&quot; - JAXB - Prevent nillable attributes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" 我不能在XML模式中包含属性。 (使用http://www.w3.org/2001/XMLSchema-instance) - I can't include attribute in my XML Schema. (http://www.w3.org/2001/XMLSchema-instance used)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM