2011-04-21 4 views
3

다음 xml 스키마를 구문 분석하면xml 열거 형 및 공용 형식의 단순 형식

요소 특성 : 스키마 구문 분석기 오류 : 특성 선언이 생성됩니다. 'current-state', attribute 'type': QName 값 'covered-state'가 (n) 단순 유형 정의로 해석되지 않습니다. WXS 스키마 memory.xsd 컴파일하는 데 실패

을 heres 책임 코드 : XML 파일이 "0"을 받아들이도록

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://www.example.com"> 

    <xsd:simpleType name="covered-state"> 
     <xsd:union> 
      <xsd:simpleType> 
       <xsd:restriction base="xsd:integer"> 
        <xsd:enumeration value="0"/> 
        <xsd:enumeration value="1"/> 
       </xsd:restriction> 
      </xsd:simpleType> 
      <xsd:simpleType> 
       <xsd:restriction base="xsd:string"> 
        <xsd:enumeration value="COVERED"/> 
        <xsd:enumeration value="UNCOVERED"/> 
       </xsd:restriction> 
      </xsd:simpleType> 
     </xsd:union> 
    </xsd:simpleType> 

    <xsd:complexType name="MemoryCard"> 
     <xsd:attribute name="current-state" type="covered-state" use="required"/> <!-- here i get the error --> 
    </xsd:complexType> 

</xsd:schema> 

그래서 이것은 어떻게해야 무엇 문자열과의 int의 열거 노동 조합이다 속성 현재 상태에 대해 "1"또는 "COVERED"또는 "UNCOVERED".

누군가 나를 올바른 방향으로 안내 할 수 있습니까? 감사!

+0

음 괜찮아요. 나는 이미 작동하도록 만들었습니다. ID는 답변을 게시하고 싶지만 새 사용자 ID는 8 시간을 더 기다려야합니다. 아마 내가 그걸 게시 할 것임을 기억한다면. 어쩌면 비슷한 문제를 가진 사람을 도울 수 있습니다. – hooch

답변

5

제안도 작동합니다하지만 난 이런 식으로 해결 :

<xsd:attribute name="current-state" use="required"> 
     <xsd:simpleType>  
      <xsd:union> 
       <xsd:simpleType> 
        <xsd:restriction base="xsd:integer"> 
         <xsd:enumeration value="0"/> 
         <xsd:enumeration value="1"/> 
        </xsd:restriction> 
       </xsd:simpleType> 
       <xsd:simpleType> 
        <xsd:restriction base="xsd:string"> 
         <xsd:enumeration value="COVERED"/> 
         <xsd:enumeration value="UNCOVERED"/> 
        </xsd:restriction> 
       </xsd:simpleType> 
      </xsd:union> 
     </xsd:simpleType> 
    </xsd:attribute> 

감사 어쨌든!

2

type="covered-state"은 네임 스페이스가없는 형식에 대한 참조이지만 네임 스페이스 "http://www.example.com"에 로컬 이름이 "covered-state" 인 형식에 대한 참조를 원합니다. 이 네임 스페이스에 접두사 (예 : e)를 바인드하고이를 으로 참조해야합니다.

+0

또는'xsd : schema' 요소에서 대상 네임 스페이스를 제거 할 수 있습니다. 네임 스페이스가 실제로 중요한지 여부에 달렸습니다. –