2013-06-26 4 views
0

내 xml 용 xsd 문서를 정의하려고합니다.이 xml에 대해 xsd를 정의하는 방법

그러나 나는 그것에 대해 새롭고 약간의 시도 후에 혼란 스럽습니다.

내 XML :

<?xml version="1.0" encoding="utf-8"?> 
<mashhadhost xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com mhost.xsd"> 
    <create> 
     <name>example.ir</name> 
     <period>60</period> 
     <ns> 
      <hostAttr> 
       <hostName>ns1.example.ir</hostName> 
       <hostAddr ip="v4">192.0.2.2</hostAddr> 
      </hostAttr> 
     </ns> 
     <contact type="holder">ex61-irnic</contact> 
     <contact type="admin">ex61-irnic</contact> 
     <contact type="tech">ex61-irnic</contact> 
     <contact type="bill">ex61-irnic</contact> 
    </create> 
    <auth> 
     <code>TOKEN</code> 
    </auth> 
</mashhadhost> 

당신이 <create><auth> 차일가 볼 수 있습니다.

1- <auth> -><code>도 필요하며 코드 길이는 32입니다.

2- <create>

2-4 시간 사이에 반복 <update> 또는 <delete>

-3- <hostAttr>으로 대체 될 수있다.

4- <contact>은 정확한 속성으로 4 회 반복해야합니다.

내 시도이지만 거기에는 많은 구멍이 있습니다.

<?xml version="1.0"?> 

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://www.w3schools.com" 
xmlns="http://www.w3schools.com" 
elementFormDefault="qualified"> 


    <xs:element name="mashhadhost"> 
     <xs:complexType> 
      <xs:sequence> 


       <xs:element name="create"> 
        <xs:complexType> 
         <xs:sequence> 
          <xs:element name="name" type="xs:string"/> 
          <xs:element name="period" type="xs:string"/> 

          <xs:element name="ns"/> 

          <xs:element name="contact" type="xs:string"/> 

         </xs:sequence> 
        </xs:complexType> 
       </xs:element> 


       <xs:element name="auth"> 
        <xs:complexType> 
         <xs:sequence> 
          <xs:element name="code" type="xs:string"/> 
         </xs:sequence> 
        </xs:complexType> 
       </xs:element> 


      </xs:sequence> 
     </xs:complexType> 
    </xs:element> 



</xs:schema> 

답변

1

귀하의 요구 사항에 따라 XSD를 만들었습니다. 이 online validator을 사용하여 xml을 스키마에 대해 유효성을 검사했습니다. 건배!!!

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema id="mashhadhost" targetNamespace="http://www.w3schools.com" xmlns:mstns="http://www.w3schools.com" xmlns="http://www.w3schools.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified"> 
<xs:complexType name="bodyType" mixed="true"> 
      <xs:sequence> 
       <xs:element name="name" type="xs:string" minOccurs="0" /> 
       <xs:element name="period" type="xs:string" minOccurs="0" /> 
       <xs:element name="ns" minOccurs="0" maxOccurs="unbounded"> 
       <xs:complexType> 
        <xs:sequence> 
        <xs:element name="hostAttr" minOccurs="2" maxOccurs="4"> 
         <xs:complexType> 
         <xs:sequence> 
          <xs:element name="hostName" type="xs:string" minOccurs="1" /> 
          <xs:element name="hostAddr" nillable="true" minOccurs="1"> 
          <xs:complexType> 
           <xs:simpleContent msdata:ColumnName="hostAddr_Text" msdata:Ordinal="1"> 
           <xs:extension base="xs:string"> 
            <xs:attribute name="ip" form="unqualified" type="xs:string" /> 
           </xs:extension> 
           </xs:simpleContent> 
          </xs:complexType> 
          </xs:element> 
         </xs:sequence> 
         </xs:complexType> 
        </xs:element> 
        </xs:sequence> 
       </xs:complexType> 
       </xs:element> 
       <xs:element name="contact" minOccurs="4" maxOccurs="4"> 
       <xs:complexType> 
        <xs:simpleContent msdata:ColumnName="contact_Text" msdata:Ordinal="1"> 
        <xs:extension base="xs:string"> 
         <xs:attribute name="type" form="unqualified" type="xs:string" /> 
        </xs:extension> 
        </xs:simpleContent> 
       </xs:complexType> 
       </xs:element> 
      </xs:sequence> 
      </xs:complexType> 
    <xs:element name="mashhadhost"> 
    <xs:complexType> 
     <xs:choice minOccurs="0" maxOccurs="unbounded"> 
     <xs:element name="create" type="bodyType"/> 
     <xs:element name="udpate" type="bodyType"/> 
     <xs:element name="delete" type="bodyType"/> 
     <xs:element name="auth"> 
      <xs:complexType> 
      <xs:sequence> 
       <xs:element name="code" minOccurs="0" > 
       <xs:simpleType> 
        <xs:restriction base="xs:string"> 
        <xs:length value="32"/> 
       </xs:restriction> 
       </xs:simpleType> 
       </xs:element> 
      </xs:sequence> 
      </xs:complexType> 
     </xs:element> 
    </xs:choice> 
    </xs:complexType> 
    </xs:element> 
</xs:schema> 
관련 문제