How to reference element in other XSD's namespace?

后端 未结 1 374
北海茫月
北海茫月 2021-01-25 01:31

I have a complexType that\'s defined across two .XSD files.

Parent.xsd:




        
相关标签:
1条回答
  • 2021-01-25 02:04

    If you want the first embedded to be in the urn:Embedded namespace along with the second embedded, you can move it there via xs:element/@ref:

    Parent.xsd

    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="urn:Parent"
               xmlns:emb="urn:Embedded"
               targetNamespace="urn:Parent"
               elementFormDefault="qualified"              
               attributeFormDefault="unqualified">
    
      <xs:import namespace="urn:Embedded" schemaLocation="Embedded.xsd"/>
    
      <xs:element name="ParentType">
        <xs:complexType>
          <xs:sequence>
            <xs:element ref="emb:embedded"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>
    

    Embedded.xsd

    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
               xmlns:emb="urn:Embedded"
               targetNamespace="urn:Embedded" 
               elementFormDefault="qualified"
               attributeFormDefault="unqualified">
    
      <xs:element name="embedded" type="emb:EmbeddedType"/>
    
      <xs:complexType name="EmbeddedType">
        <xs:sequence>
          <xs:element name="numeric" type="xs:int"/>
          <xs:element name="embedded" type="emb:EmbeddedType" 
                      minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
      </xs:complexType>
    </xs:schema>
    

    XML

    <?xml version="1.0" encoding="utf-8"?>
    <ParentType xmlns="urn:Parent" 
                xmlns:emb="urn:Embedded"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="urn:Parent Parent.xsd">
      <emb:embedded>
        <emb:numeric>12</emb:numeric>
        <emb:embedded>
          <emb:numeric>5</emb:numeric>
        </emb:embedded>
      </emb:embedded>
    </ParentType>
    
    0 讨论(0)
提交回复
热议问题