2017-09-17 3 views
0

나는 XSD 스키마를 사용하여 XML 파일에 대한 다음과 같은 구조를 구현하는 가장 좋은 방법을 찾기 위해 노력하고 있어요 :XSD 순서

그래서
<Vertice></Vertice> 
<Edge></Edge> 
...any number of Vertices and Edges between... 
<Vertice></Vertice> 
<Edge></Edge> 

항상 있어야합니다 시작 - 정점, 최종 정점과 그 사이에 하나의 Edge가 있지만 필요에 따라 중간에 많은 Vertices를 포함 할 수 있습니다. 각 가장자리는 Edges로 둘러싸여 있습니다 (XML은 나중에이 구성표를 기반으로 JAXB에서 생성됩니다). 이 같은 것을 사용하려고했지만 컴파일되지 않았습니다. 그것을 구현할 수있는 적절한 방법이 있습니까?

<?xml version="1.0" encoding="UTF-8" ?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

    <!-- declaration --> 
    <xs:complexType name="graphType"> 
     <xs:sequence minOccurs="1" maxOccurs="unbounded"> 
      <xs:element name="vertice" type="xs:string"/> 
      <xs:element name="edge" type="xs:string"/> 
     </xs:sequence> 
     <xs:element name="vertice" type="xs:string"/>  <!-- this line is not working --> 
    </xs:complexType> 

    <!-- printing --> 
    <xs:element name="Graph" type="graphType"/> 

</xs:schema> 

나는 그래서 내가 마지막 정점의 이름을 변경해야합니다,이 같은 뭔가를 알아 낸 있지만 다시 한 번 같은 이름을 사용하도록 허용하지 않는다. 그러나 이것에 대한 해결책을 찾을 수있는 방법이 있습니까?

<?xml version="1.0" encoding="UTF-8" ?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

    <!-- declaration --> 
    <xs:complexType name="graphType"> 
     <xs:sequence> 
      <xs:sequence minOccurs="2" maxOccurs="unbounded"> 
       <xs:element name="vertice" type="xs:string"/> 
       <xs:element name="edge" type="xs:string"/> 
      </xs:sequence> 
      <xs:element name="vertice-end" type="xs:string"/> 
      <!-- is there a workaround to repeat the name "vertice" for this element? --> 
     </xs:sequence> 
    </xs:complexType> 

    <!-- printing --> 
    <xs:element name="Graph" type="graphType"/> 

</xs:schema> 

답변

0

단순히 그것을 다른 방법, 즉 vertice로 시작해야합니다 모델을 생각을하고 edge + vertice의 순서는 (가, 동일 그렇지?)입니다. 이렇게하면 항상 vertice 요소로 끝납니다.

<?xml version="1.0" encoding="UTF-8" ?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

    <!-- declaration --> 
    <xs:complexType name="graphType"> 
     <xs:sequence> 
      <xs:element name="vertice" type="xs:string"/> 
      <xs:sequence minOccurs="1" maxOccurs="unbounded"> 
       <xs:element name="edge" type="xs:string"/> 
       <xs:element name="vertice" type="xs:string"/> 
      </xs:sequence> 
     </xs:sequence> 
    </xs:complexType> 

    <!-- printing --> 
    <xs:element name="Graph" type="graphType"/> 

</xs:schema> 

당신은 고유 입자 저작자라는 문제에 직면 할 가능성이 있었다, 여기 https://www.w3.org/wiki/UniqueParticleAttribution를 더 읽기 (또는 당신의 자신의 검색을 할) 수 있습니다.

+0

대단히 감사합니다. 물론 필자가 필요로하는 결과에 부합합니다. 그러나 시퀀스 이후에 vertice 요소가 추가되었을 때 컴파일되지 않은 이유를 알 수 없습니다. 시퀀스 이전 일 때 - XSD의 일부 마법을 기억해야합니다 :) 또는 간단합니다. 그것의 설명? – Piotr

+0

실제로 하나 더 문제가 생겼습니다 - 다음으로 XJC를 사용하여 Java 클래스를 생성하는 것이 었습니다.하지만 '[ERROR] Element "vertice"가 둘 이상의 속성에 표시되는 오류가 발생합니다. 관련성이 있다면 내 XJC 버전은'xjc 2.2.8-b130911.1802'입니다. 거기에 해결 방법을 적용 할 방법이 있습니까? – Piotr

+0

안녕하세요 - 첫 번째 의견과 관련하여 답변 끝에 제공된 링크를 살펴 보시기 바랍니다. 왜 그런지 이해하지 못했던 이유에 대한 설명입니다. 두 번째 의견에 관해서는 새로운 질문을해야한다고 생각합니다. – potame