2013-01-22 5 views
1

XSD 파일에서 '제한되지 않은'여러 시간을 발생할 수있는 두 요소를 정의하고 싶습니다. 그러나 항상 뒤따라야합니다. 예 :XSD를 사용하여 XML에서 요소를 교대로 정의하는 방법

XML 파일 :

<company/> 
<address/> 
<customer/> 
<customerContact/> 
<customer/> 
<customerContact/> 
<customer/> 
<customerContact/> 

이제 문제는, 다음과 같은 XSD 정의

<xs:element name="company" type="companyType"/> 
<xs:element name="address" type="addressType"/> 
<xs:element name="customer" type="customerType" maxOccurs="unbounded"/> 
<xs:element name="customerContact" type="customerContactType" maxOccurs="unbounded"/> 

<company/> 
<address/> 
<customer/> 
<customer/> 
<customer/> 
<customerContact/> 
<customerContact/> 
<customerContact/> 

같은 XML 파일과 함께 작동하는지 고객customerConta ct 대체하지 마십시오. 고객에게또는고객 문의이라는 요소를 정의하고 해당 요소를 반복 할 수있는 아이디어가있었습니다. 그건 내 문제를 해결할 수 있지만, 그것은 또한 유효한 것으로 받아 들여서는 안되는 다른 솔루션을 허용합니다.

나는 깨끗한 솔루션은 XML

같은
<company/> 
<address/> 
<customerEnvelope> 
    <customer/> 
    <customerContact/> 
<customerEnvelope> 
<customerEnvelope> 
    <customer/> 
    <customerContact/> 
</customerEnvelope> 

을 가지고 customerEnvelope을 반복하는 것입니다 생각합니다. 불행히도 XML 구조는 이미 고객이 제공하고 있으므로 여기서 변경할 수는 없습니다.

XSD를 사용하여 이러한 종류의 구조를 정의 할 수 있습니까? 아니면 위에서 언급 한 해결 방법을 사용해야합니까?

답변

3
<xs:element name="company" type="companyType"/> 
<xs:element name="address" type="addressType"/> 
<xs:sequence maxOccurs="unbounded"> 
    <xs:element name="customer" type="customerType"/> 
    <xs:element name="customerContact" type="customerContactType"/> 
</xs:sequence> 
+0

정말 간단한 해결책이었습니다. 때로는 가장 분명한 사실이 있습니다. @ 13ren 대단히 감사합니다! –

+0

@MathiasBader 덕분에 XSD는 어떤 점에서 꽤 좋습니다. BTW : 당신은 그것을 정규 표현식'ab (cd) *'와 같이 생각할 수 있습니다. – 13ren

관련 문제