비 결정적 발생 요소가있는 XML 파일의 XSD 유효성 검증
-
19-09-2019 - |
문제
다음 XML 스 니펫은 표준 XML LIB (Java 및 Scala로 시도)를 사용하여 파싱 가능합니다.
<?xml version="1.0" encoding="UTF-8"?>
<list>
<a>value1</a>
<b>value2</b>
<a>value3</a>
<a>value4</a>
<a>value5</a>
<b>value6</b>
<b>value7</b>
</list>
보시다시피 'A'와 'B'요소는 혼합되어 있습니다 (비 결정적). 이 "혼합 된"동작에 대해 XSD를 작성할 수 있습니까?
해결책
이것은 작동해야합니다 .. :-)
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="list">
<xs:complexType>
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element name="a" type="xs:string" />
<xs:element name="b" type="xs:string" />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
제휴하지 않습니다 StackOverflow