2017-03-09 1 views
-1

xml 및 schema를 학습 중입니다. 전화 요소 값이 고유해야하는 스키마가 필요합니다. 나는 독특한 것으로 시도하지만 어떻게 작동하는지 이해할 수는 없습니다. 이 바보 같은 질문에 대해 유감스럽게 생각하지만 저는 배웁니다.전화 요소에 대해 고유 한 값을 원합니다.

XML

<?xml version="1.0" encoding="utf-8" ?> 
<Company xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <Employee> 
    <Name>ABC</Name> 
    <Telephone>9998887770</Telephone> 
    </Employee> 
    <Employee> 
     <Name>DEF</Name> 
     <Telephone>9998887770</Telephone> 
    </Employee> 
    <Employee> 
     <Name>GHI</Name> 
     <Telephone>1234567890</Telephone> 
    </Employee> 
</Company> 

스키마

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema id="EmployeeSchema" 
     elementFormDefault="qualified" 
     attributeFormDefault="unqualified" 
     xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

    <xs:element name="Name"/> 
    <xs:element name="Telephone" /> 

    <xs:simpleType name="string32"> 
     <xs:restriction base="xs:token"> 
     <xs:maxLength value="32"/> 
    </xs:restriction> 

    <xs:element name="Company"> 
     <xs:complexType> 
      <xs:sequence> 
       <xs:element ref="Employee" maxOccurs="unbounded"/> 
      </xs:sequence> 
     </xs:complexType> 
    <!--Here i try to implement unique---> 
     <xs:unique name="Company"> 
      <xs:selector xpath="Telephone"/> 
      <xs:field xpath="Telephone"/> 
     </xs:unique> 
    </xs:element> 

     <xs:element name="Employee"> 
      <xs:complexType> 
      <xs:sequence>  
       <xs:element ref="Name"/> 
       <xs:element ref="Telephone"/>  
      </xs:sequence> 
     </xs:complexType> 
     </xs:element> 
</xs:schema> 
+0

"나는 독특하지만 어떻게 작동하는지 이해할 수 없습니다." 어떤 책을 읽었습니까? Priscilla Walmsley를 추천합니다. <: 내가 ** @MichaelKay –

+0

/xs : complexType> __ 여기에 코드를 작성해도 여전히 작동하지 않습니다 .__ ** –

답변

1

<xs:unique name="Company-Employee-Phone"> 
    <xs:selector xpath="Employee"/> 
    <xs:field xpath="Telephone"/> 
</xs:unique> 

규칙 시도는 이것이다 : 당신은 X 내 모든 Y를 원하는 경우 별개의 값을 가지도록 Z에 대한 다음, defin X 정의에서 xs:unique 제한 조건을 사용하려면 X에서 Y를 xs:selector으로 선택하는 경로와 Y에서 Y를 xs:field으로 선택하는 경로를 사용하십시오.

+0

** <요소 이름 = "직원"XS> "에릭 반 데르 VLIST하여 XML 스키마"**에서 배우고 –

+0

그런 다음 내 대답을 다시 읽으십시오. X = Company, Y = Employee, Z = Telephone이므로 X = Company에 제약 조건이 적용됩니다. –

관련 문제