2011-11-17 2 views
0

허용되는 속성의 긴 목록이있는 attributeGroup은 다음과 같이 말합니다. a : attr-group, 다른 xsd로 가져 와서 요소의 (다른 xsd에 정의 된) 허용 된 속성을 제한합니다.여러 개의 네임 스페이스에 xs : attributeGroups 가져 오기 xsd

동일한 요소가 두 번째 네임 스페이스 인 b : attr-group에서 동일한 속성을 사용하도록하고 모든 속성 및 그룹 정의를 반복하지 않고 동일한 파일을 사용하고자합니다.

간단한 방법이 있나요? 지금까지의 모든 시도는 가져 오기 네임 스페이스가 targetNamespace 규칙과 동일해야합니다.

미리 감사드립니다.

답변

2

이 패턴은 카멜레온라고도합니다. 즉 이고을 포함한다는 의미이며 대상 네임 스페이스가없는 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 Schema files layout

샘플 : 유효하지 않은 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이 (가) 잘못되었습니다.

+0

신속한 답장을 보내 주셔서 감사합니다. 저에게 두 가지 요소 정의를 제공하지 않습니까? 두 스키마 모두에 대해 xml을 독립적으로 검증해야합니까? – Arth

+0

a.xsd 및 b.xsd에 대해 유효성을 검사 할 XML 문서의 예제를 제공 할 수 있습니까? test.xml을 사용해 보았습니다 : < 요소 xmlns : a = "http://tempuri.org/XMLSchema.xsd/a"xmlns : b = "http://tempuri.org/XMLSchema.xsd/b"elementFormDetail = "부적합"a : attr1 = "a "b : attr2 ="b "/>'그러나 '요소'를 해결할 수 없습니다 – Arth

+0

감사합니다. 매우 명확하고 잘 설명 된 답변 - 건배! – Arth

관련 문제