xsd - 这个 XSD 导入命名空间有什么用?

标签 xsd xml-namespaces

我有一个以以下内容开头的 xsd 文档:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:import namespace="http://www.w3.org/XML/1998/namespace"     schemaLocation="http://www.w3.org/2001/xml.xsd"/>
    <xs:complexType name="T_segment">
        <xs:sequence>
            <xs:element ref="element" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute ref="xml:space" use="required"/>
        <xs:attribute ref="id" use="required"/>
    </xs:complexType>
...

当我尝试在像 BizTalk 这样的映射应用程序中使用这个 xsd 时,它会提示命名空间。所以,我删除了 xs:import 命名空间标记,它提示 xs:attribute ref="xml:space"标记。所以,我删除了它,它似乎工作正常(至少不会爆炸)。

我的问题是,这些标签是做什么用的?通过删除它们,我是否破坏了 xsd?

据我所知,命名空间是为了避免冲突。但是在 xsd 中,所有内容都以 xs 为前缀,并且架构本身具有 xmlns:xs="http://www.w3.org/2001/XMLSchema"。我不确定那个导入是做什么用的。

最佳答案

<xs:import /> element 将 XML 命名空间导入到架构中。导入的命名空间包含“space”属性的定义。 <xs:attribute ref="xml:space" use="required"/> bit 通过从导入的模式中引用来定义“T_segment”复杂类型所需的“空间”属性(即,您不必重写定义)。 space 属性本质上使您能够定义 whitespace is significant for the element or not .

现在,根据应用程序,您实际上可能会破坏一些事情,因为本质上您正在从复杂类型中删除可能与使用此模式描述的文档的应用程序相关的约束。在不了解更多应用程序的情况下,很难说这对您的情况是否重要。

关于xsd - 这个 XSD 导入命名空间有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2120562/

相关文章:

Spring 自定义命名空间 - 用例

java.xml.Validator : xsi:schlemaLocation is ignored when namespaces are present

java - 使用 java 从 .xsd 创建 .xml 文件

.net - 当属性已声明为父级的属性时,使用 XPath 匹配名称格式为 ParentElement.Property 的元素

java - 改进 xsd :any in Java code 的使用

android - XML 错误 : error: not well-formed (invalid token) in splash screen (React Native)

xml - 将元素插入 xml 会产生不必要的属性 xmlns=

xml - 使用 xslt 重命名元素

java - 使用 JAXB 从 XSD 生成元素 java 类

c# - 使用 XSD.exe 为引用类型生成 minOccurs = 1 的不可空字段