2011-08-09 2 views
1

'개체'노드의 하위 노드를 '텍스트'또는 '이미지'노드로 만들 수있는 방법을 고안했습니다. 횟수와 순서에 관계없이 '객체'노드에 표시되는 순서에 따라 렌더링 방법이 결정되지만 순서를 확인할 필요가 없습니다.임의의 순서로 여러 번 나타나는 혼합 된 콘텐츠가있는 XSD 노드

예 1

<objects> 
    <textobject x="30" y="100" value="blah1" /> 
    <imageobject x="0" y="0" src="/path/to/some/image1.png"/> 
    <imageobject x="0" y="0" src="/path/to/some/image2.png"/> 
    <textobject x="60" y="250" value="blah2" /> 
    <textobject x="60" y="250" value="blah3" /> 
</objects> 

예 2

<objects> 
    <imageobject x="0" y="0" src="/path/to/some/image1.png"/> 
    <textobject x="30" y="100" value="blah1" /> 
    <textobject x="60" y="250" value="blah2" /> 
    <imageobject x="0" y="0" src="/path/to/some/image2.png"/> 
    <textobject x="60" y="250" value="blah3" /> 
</objects> 

감사합니다!

답변

1

당신은 minOccurs="0"maxOccurs="unbounded"xs:choice을 사용할 수

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> 
    <xs:element name="objects"> 
    <xs:complexType> 
     <xs:choice minOccurs="0" maxOccurs="unbounded"> 
     <xs:element ref="imageobject"/> 
     <xs:element ref="textobject"/> 
     </xs:choice> 
    </xs:complexType> 
    </xs:element> 
    <xs:element name="imageobject"> 
    <xs:complexType> 
     <xs:attribute name="src" use="required"/> 
     <xs:attribute name="x" use="required" type="xs:integer"/> 
     <xs:attribute name="y" use="required" type="xs:integer"/> 
    </xs:complexType> 
    </xs:element> 
    <xs:element name="textobject"> 
    <xs:complexType> 
     <xs:attribute name="value" use="required"/> 
     <xs:attribute name="x" use="required" type="xs:integer"/> 
     <xs:attribute name="y" use="required" type="xs:integer"/> 
    </xs:complexType> 
    </xs:element> 
</xs:schema> 
+0

고마워요, 내게 준 : 복구 할 수있는 구문 분석 오류 : org.xml.sax.SAXParseException : src-resolve : 'imageobject'라는 이름을 '요소 선언'구성 요소로 해결할 수 없습니다. 복구 할 수있는 구문 분석 오류 : org.xml.sax.SAXParseException : src-resolve : 'textobject'이름을 (n) '요소 선언'구성 요소로 해석 할 수 없습니다. SAXException : cvc-complex-type.2.4.d : 'imageobject'요소로 시작하는 잘못된 내용이 발견되었습니다. 이 시점에서 하위 요소는 필요하지 않습니다. – kreek

+0

제공된 스키마가 유효합니다 - Saxon에서 테스트했습니다. 아마도 당신은 그것을 어떤 식 으로든 변경했을 것입니다. 네임 스페이스를 추가하여. –

1

<xs:choice maxOccurs="unbounded">을 사용하십시오.

3

을이 상황에서가 아니라 대체 그룹을 사용하는 것이 적절할 수있다. "textObject"및 "imageObject"를 해당 대체 그룹의 구성원으로 사용하여 "mediaObject"를 추상 요소로 정의한 다음 내용 모델을 <xs:element ref="mediaObject" minOccurs="0" maxOccurs="unbounded"/>으로 정의하십시오. 이 디자인의 이점은 확장 성이 뛰어나고 관심사를 분리하고 의미 체계를보다 잘 표현하며 정의를 재사용 할 수 있다는 것입니다. 이 혜택은 2 가지가 아니라 15 가지 종류의 미디어 객체가 실제로 나타나기 시작합니다.

+0

우수 제안. –

관련 문제