2011-11-30 3 views
3

부분적으로 파일의 유효성을 검사 할 XSD 스키마를 준비해야합니다. 파일 구조는 다음과 같습니다 유엔 명 <xs:element>가 유효하지 않은, 완전히 올바른 불완전하고하지정의되지 않은 내용이있는 XSD 요소

<xs:element name="Root"> 
    <xs:complexType> 
     <xs:sequence maxOccurs="unbounded"> 
      <xs:element name="Node"> 
       <xs:complexType> 
        <xs:sequence> 
         <xs:element maxOccurs="unbounded" /> 
        </xs:sequence>       
        <xs:attribute name="name" type="xs:string" /> 
       </xs:complexType> 
      </xs:element> 
     </xs:sequence> 
    </xs:complexType> 
</xs:element> 

:

<Root> 
    <Node name="core"> 
     <ElementA>String</ElementA> 
     <ElementB>String</ElementB> 
    </Node> 
    <Node name="something unique"> 
     (any number of elements, with unknown names and types) 
    </Node> 
</Root> 

내 XSD 뭔가 같다.

필요로하는 노드가 몇 개 있으며 각 노드에는 고유 한 이름 특성이 있습니다. 이것이 제가 검증하고자하는 것입니다. 이름 목록과 해당 노드의 내용은 미리 정의되어 있습니다.

알 수없는 이름을 가진 노드의 내용도 알 수 없으며 임의의 수와 유형의 요소가 포함될 수 있지만 속성이나 값 자체는 없어야합니다.

문제가있는 부분은 이름을 모른 채 하위 요소를 허용하는 부분입니다.

XSD에서 이와 같은 작업을 수행 할 수 있습니까? 복잡한 유형의 요소 또는 anyType 및 특성을 갖는 방법이 있습니까?

편집 : 그것은 요소 유형으로 <Node>name의를 사용하는만큼 받아 들일 수하고 간단하게 알 수없는 이름을 가진 추가 요소를 허용합니다. 어느 쪽이든, 알 수없는 이름과 유형의 노드를 허용해야합니다.

답변

8

"이름을 알지 못하는 자식 요소"를 허용하려면 xsd : any를 사용할 수 있습니다. ("디자인 타임"으로 알려진) 내용 뒤에 반복되는 입자로 추가하십시오.

<?xml version="1.0" encoding="utf-8"?> 
<!--W3C Schema generated by QTAssistant/W3C Schema Refactoring Module (http://www.paschidev.com)--> 
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <xsd:element name="Root"> 
    <xsd:complexType> 
     <xsd:sequence> 
     <xsd:element name="Node"> 
      <xsd:complexType> 
      <xsd:sequence> 
       <xsd:element name="ElementA" type="xsd:string" /> 
       <xsd:element name="ElementB" type="xsd:string" /> 
      </xsd:sequence> 
      <xsd:attribute name="name" type="xsd:string" use="required" /> 
      </xsd:complexType> 
     </xsd:element> 
     <xsd:element name="Extensions" minOccurs="0"> 
      <xsd:complexType> 
       <xsd:sequence> 
        <xsd:any maxOccurs="unbounded"  processContents="lax"/> 
       </xsd:sequence> 
       <xsd:anyAttribute processContents="lax"/> 
      </xsd:complexType> 
     </xsd:element> 
     </xsd:sequence> 
    </xsd:complexType> 
    </xsd:element> 
</xsd:schema> 
+0

필수 요소와 선택적 요소를 구별하는 것이 좋습니다. 이 경우 이름이 두 개 이상입니까? – ssube

+0

예. 그러나 xsd : any를 래퍼 요소 아래에 두지 않아도된다. 그러나 이것은 다소 일반적인 패턴입니다. 한 가지 내가 다르게 할 것이지만 Extensions 요소에 대해 글로벌 복합 유형을 정의하여 스키마를 사용하는 누군가가 "강력한 유형"으로하려는 경우 자신의 재정의를 수행 할 수 있도록 허용하는 것입니다. 나는 xsd : any가 어떻게 내가 당신을 이해할 수있는 방식으로 당신의 요구 사항을 만족시킬 수 있었는지를 당신에게 빨리 보여 주려고했다. –