2013-09-05 5 views
0

우리가 RPC를 만드는 데 사용하는 (사용자 정의) XML 프로토콜을 설명하려고 할 때 XSD에 자신을 던지고 있습니다. 상기XSD 상속, 확장 또는 다른 것?

<command type="request" lineid="500477"> 
    <request name="ping"> 
     <node id="503456" device="meter"/> 
    </request> 
</command> 


<command type="response" lineid="500477"> 
    <response name="ping"> 
     <result>true</result> 
    </response> 
</command> 

다운 트리밍 예를하고, 또한, 상기 요청 노드는 매개 요소들의리스트를 포함 할 수 있으며, 그 결과 노드 고급 포함될 수

간단한 요청/응답 쌍과 같다 다른 요청 유형에 대한 데이터.

위의 내용을 XSD로 설명하려고하지만 요청/응답의 동적 특성을 설명하는 방법을 알 수 없습니다.

xs : complexType을 상속하고 중첩하려했지만 "올바른 방법"이 아닌 것으로 보입니다.

나의 현재 시도 : 나는 어떻게 요청 및 일반 명령 노드 내부 응답 요소 모두를 허용하는 아무 생각이

<?xml version="1.0"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:complexType name="request"> 
     <xs:attribute name="name" type="xs:string" use="required"/> 
    </xs:complexType> 
    <xs:complexType name="command" mixed="true"> 
     <xs:sequence> 
      <xs:element name="request" type="request"></xs:element> 
     </xs:sequence> 
     <xs:attribute name="type" type="commandtype" use="required"/> 
     <xs:attribute name="lineid" type="xs:string"/> 
    </xs:complexType> 
    <xs:simpleType name="commandtype"> 
     <xs:restriction base="xs:string"> 
      <xs:enumeration value="request"/> 
      <xs:enumeration value="response"/> 
     </xs:restriction> 
    </xs:simpleType> 

    <xs:element name="command" type="command" /> 
</xs:schema> 

에도이 단계에서.

위에서 XSD를 어떻게 설명해야합니까?

이 부분에서

답변

1

, 요청 및 응답을 모두 넣어하지만 그들을 선택합니다

<xs:sequence> 
    <xs:element name="request" type="request" use="optional"></xs:element> 
    <xs:element name="response" type="request" use="optional"></xs:element> 
</xs:sequence> 

경고, 나는 메모리에서 XSD를 입력 잘하지, 그래서이 정확히 맞지 않을 수 있지만 원리는 내가 너에게 보여주고 자하는 것.

이렇게하면 하나 또는 둘 다를 가질 수 있습니다. (또는 둘 다 할 수도 있고 둘 다 할 수도 있지만 코드에 해당 테스트를 추가 할 수 있으며 XSD가 테스트를 지정하지 않거나 둘 다 수행하지 마십시오.)