이 패턴은 카멜레온라고도합니다. 즉 이고을 포함한다는 의미이며 대상 네임 스페이스가없는 XML 스키마 인 경우 은 부모 스키마의 네임 스페이스라고 가정합니다.
UPDATE :
먼저 스키마 파일 (AttrGroup.xsxd) :
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema
elementFormDefault="qualified" attributeFormDefault="qualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:attributeGroup name="attr-group">
<xsd:attribute name="attr1" type="xsd:string"/>
<xsd:attribute name="attr2" type="xsd:int"/>
</xsd:attributeGroup>
</xsd:schema>
두 번째 스키마 파일 (A.xsd) :
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd/a"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema.xsd/a"
xmlns:a="http://tempuri.org/XMLSchema.xsd/a"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:include schemaLocation="AttrGroup.xsd"/>
<xsd:attributeGroup name="a-group">
<xsd:attributeGroup ref="attr-group"/>
</xsd:attributeGroup>
</xsd:schema>
코멘트에 제공되는 샘플 XML을 고려
세 번째 스키마 파일 (B.xsd) :
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd/b"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema.xsd/b"
xmlns:b="http://tempuri.org/XMLSchema.xsd/b"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:include schemaLocation="AttrGroup.xsd"/>
<xsd:attributeGroup name="b-group">
<xsd:attributeGroup ref="attr-group"/>
</xsd:attributeGroup>
</xsd:schema>
네 번째 XML 스키마 (Element.xsd) : 유효한 XML의
<?xml version="1.0" encoding="utf-8"?>
<!--XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com)-->
<xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:a="http://tempuri.org/XMLSchema.xsd/a" xmlns:b="http://tempuri.org/XMLSchema.xsd/b">
<xsd:import namespace="http://tempuri.org/XMLSchema.xsd/a" schemaLocation="A.xsd"/>
<xsd:import namespace="http://tempuri.org/XMLSchema.xsd/b" schemaLocation="B.xsd"/>
<xsd:element name="element">
<xsd:complexType>
<xsd:attributeGroup ref="a:a-group"/>
<xsd:attributeGroup ref="b:b-group"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
샘플 : 유효하지 않은 XML의
<element xmlns:a="http://tempuri.org/XMLSchema.xsd/a" xmlns:b="http://tempuri.org/XMLSchema.xsd/b" a:attr1="hello" b:attr2="10" />
샘플 :
<element xmlns:a="http://tempuri.org/XMLSchema.xsd/a" xmlns:b="http://tempuri.org/XMLSchema.xsd/b" a:attr1="hello" b:attr2="10a" />
에 대해 검증 Element.xsd 잘못된 샘플,이 오류가 나타납니다. 메시지 (내 도구) : [1] 라인 1의 위치를로드하는 중 오류가 발생했습니다. 'http://tempuri.org/XMLSchema.xsd/b:attr2'속성이 잘못되었습니다. - 'http://www.w3.org/2001/XMLSchema:int'데이터 유형에 따라 '10a'값이 잘못되었습니다. - '10a'문자열이 아닙니다. 유효한 Int32 값 D : ... \ SampleAttrGroup.xml이 (가) 잘못되었습니다.
신속한 답장을 보내 주셔서 감사합니다. 저에게 두 가지 요소 정의를 제공하지 않습니까? 두 스키마 모두에 대해 xml을 독립적으로 검증해야합니까? – Arth
a.xsd 및 b.xsd에 대해 유효성을 검사 할 XML 문서의 예제를 제공 할 수 있습니까? test.xml을 사용해 보았습니다 : xml version = "1.0"encoding = "UTF-8"?> < 요소 xmlns : a = "http://tempuri.org/XMLSchema.xsd/a"xmlns : b = "http://tempuri.org/XMLSchema.xsd/b"elementFormDetail = "부적합"a : attr1 = "a "b : attr2 ="b "/>'그러나 '요소'를 해결할 수 없습니다 – Arth
감사합니다. 매우 명확하고 잘 설명 된 답변 - 건배! – Arth