2014-09-04 1 views
0

은 태그 값에 조건을 추가 할 수있는 방법이 있습니까? 예를 들어, 내 XML은 다음과 같습니다xsd의 조건부 값

<Root> 
<Scheduler> 
    <DateTimeType>DAY</DateTimeType> 
    <DayOfWeek>Sunday</DayOfWeek> <!-- TAG IS ALLOWED --> 
</Scheduler> 

<Scheduler> 
    <DateTimeType>MONTH</DateTimeType> 
    <DayOfWeek>Sunday</DayOfWeek> <!-- TAG IS NOT ALLOWED --> 
    <DayOfMonth>28</DayOfMonth> <!-- TAG IS ALLOWED --> 
</Scheduler> 

<Scheduler> 
    <DateTimeType>WEEKDAY</DateTimeType> 
    <DayOfWeek>Sunday</DayOfWeek> <!-- TAG IS ALLOWED --> 
    <TimeOfDay>15:26</TimeOfDay> <!-- TAG IS ALLOWED --> 
    <DayOfMonth>28</DayOfMonth> <!-- TAG IS NOT ALLOWED --> 
</Scheduler> 

<Scheduler> 
    <DateTimeType>TIME</DateTimeType> 
    <DayOfWeek>Sunday</DayOfWeek> <!-- TAG IS NOT ALLOWED --> 
    <DayOfMonth>28</DayOfMonth> <!-- TAG IS NOT ALLOWED --> 
    <TimeOfDay>15:26</TimeOfDay> <!-- TAG IS ALLOWED --> 
</Scheduler> 
</Root> 

나는 /이 나의 XML에서 이러한 조건을 허용 할 수 XSD 제도가 필요합니다.

감사합니다.

답변

1

DateTimeType이 특성 인 경우 조건부 형식 할당을 사용하면 편리하게 수행 할 수 있습니다. 이 자식 요소해야 할 경우, 당신은 그들이 요소라고, 그들은 태그 호출되지, 그런데 예를

<xs:assertion test="not(DateTimeType = 'MONTH' and exists(DayOfWeek)"/> 

에 대한 주장을 사용하여 작업을 수행 할 수 있습니다. 요소에는 일반적으로 시작 태그와 종료 태그라는 두 개의 태그가 있습니다. 올바른 용어를 사용하면 많은 이점이 있습니다. 예를 들어, 오류 메시지에 사용 된 언어를 더 잘 이해하게 될 것입니다.