xml - XSD 如何引用不同命名空间中同名的 XML 元素

标签 xml reference xsd namespaces xml-namespaces

我有这个 XML 架构,其中包含一个序列,其中包含两个具有相同名称但 namespace 不同的引用。Address元素在 Address1.xsd 和 Address2.xsd 中定义

我想知道这是否被标准接受。

 <xsd:schema targetNamespace="http://xmlns.oracle.com/bpmn/bpmnCloudProcess/Testnamespace/Process" 
    xmlns:tns7="http://my.namespace.com2" xmlns:tns6="http://my.namespace.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

        <xsd:import namespace="http://my.namespace.com" schemaLocation="Address1.xsd"/>
        <xsd:import namespace="http://my.namespace.com2" schemaLocation="Address2.xsd"/>

        <xsd:element name="start">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element ref="tns6:Address"/>
                    <xsd:element ref="tns7:Address"/>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>

 </xsd:schema>

最佳答案

是的,你的例子是正确的 并演示了引用两个 Address 的正确方法元素通过位于不同的命名空间中来区分。只要确保 Address1.xsd 有 targetNamespace等于 http://my.namespace.com和 Address2.xsd 有一个 targetNamespace等于 http://my.namespace.com2 .以下是一致定义的所有三个 XSD:

主 XSD

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema 
     targetNamespace="http://xmlns.oracle.com/bpmn/bpmnCloudProcess/Testnamespace/Process" 
     xmlns:tns7="http://my.namespace.com2"
     xmlns:tns6="http://my.namespace.com"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <xsd:import namespace="http://my.namespace.com"
              schemaLocation="Address1.xsd"/>
  <xsd:import namespace="http://my.namespace.com2"
              schemaLocation="Address2.xsd"/>

  <xsd:element name="start">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="tns6:Address"/>
        <xsd:element ref="tns7:Address"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

</xsd:schema>

地址1.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://my.namespace.com" 
            xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <xsd:element name="Address"/>

</xsd:schema>

地址2.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://my.namespace.com2" 
            xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <xsd:element name="Address"/>

</xsd:schema>

关于xml - XSD 如何引用不同命名空间中同名的 XML 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32079794/

相关文章:

C++做引用占用内存

xsd - 格式化XSD方案以供同行评审

asp.net - 即使发现 nullException,仍继续运行代码

php - 错误 : "Input is not proper UTF-8, indicate encoding !" using PHP's simplexml_load_string

android - @layout 引用的自定义 xml 属性

xsd - 如何使用 <xs :unique> as a child element of the <xs:element> tag? 为属性指定唯一约束

java - 在 java 中使用 xml 模式创建 xml 文件

sql - 在 Oracle SQL 中选择 xpath 值作为单独的行

rust - 为什么 impl 和普通函数之间的可变引用不一致?

c++ - 引用地址