2014-09-10 1 views
0

XML 파일의 유효성을 다시 검사하는 데 문제가 있습니다. 어떤 도움이 필요합니까?XML 스키마에서 간단한 내용 태그 닫기

링크 : http://www.utilities-online.info/xsdvalidation/?save=f640c556-1da8-4cc4-a50c-b72f9d7a8780-xsdvalidation

XSD 파일 :

<?xml version="1.0"?> 

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

<xsd:element name="asdasdasdasd"> 
    <xsd:complexType> 
    <xsd:choice minOccurs="0" maxOccurs="unbounded"> 


<xsd:element name="student"> 
    <xsd:complexType> 
    <xsd:choice minOccurs="0" maxOccurs="unbounded"> 
     <xsd:element name="firstname"> 
      <xsd:simpleContent> 
       <xsd:restriction base="xsd:string"/> 
       </xsd:restriction> 
      </xsd:simpleContent> 
     </xsd:element> 
     <xsd:element name="lastname"> 
      <xsd:simpleContent> 
       <xsd:restriction base="xsd:string"/> 
       </xsd:restriction> 
      </xsd:simpleContent> 
     </xsd:element>  
      <xsd:element name="email"> 
      <xsd:simpleContent> 
       <xsd:restriction base="xsd:string"/> 
       </xsd:restriction> 
      </xsd:simpleContent> 
     </xsd:element>  
     <xsd:element name="dateofbirth"> 
      <xsd:simpleContent> 
       <xsd:restriction base="xsd:date"/> 
       </xsd:restriction> 
      </xsd:simpleContent> 
     </xsd:element>  
     <xsd:element name="major"> 
      <xsd:simpleType> 
      <xsd:simpleContent> 
       <xsd:restriction base="xsd:string"/> 
        <xsd:enumeration value="Computer Science/SD" /> 
        <xsd:enumeration value="Computer Science/IT" /> 
        <xsd:enumeration value="Math" /> 
       </xsd:restriction> 
      </xsd:simpleContent> 
      </xsd:simpleType> 
     </xsd:element> 
     <xsd:attribute name="stuid" type="xsd:integer"/> 
    </xsd:complexType> 
    </xsd:choice> 
</xsd:element> 



    </xsd:complexType> 
    </xsd:choice> 
</xsd:element> 



</xsd:schema> 

XML 파일 : 여기 바보 같은 일을 할 수 있도록

<?xml version="1.0"?> 
    <asdasd> 


    <student xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:noNamespaceSchemaLocation="http://unixweb.kutztown.edu/~agyaw792/480/hw2xsd.xsd" stuid="002"> 

      <firstname>John</firstname> 
      <lastname>Doe</lastname> 
      <email>[email protected]</email> 
      <dateofbirth>2002-09-24</dateofbirth> 
      <major>Computer Science/SD</major> 

      </student> 

      <student stuid="007"> 
      <firstname>Mary</firstname> 
      <lastname>Smith</lastname> 
      <email>[email protected]</email> 
      <dateofbirth>2004-02-32</dateofbirth> 
      <major>Computer Science/IT</major> 
      </student> 

       <student stuid="123"> 
      <firstname>Harry</firstname> 
      <lastname>Potter</lastname> 
      <email>[email protected]</email> 
      <dateofbirth>2004-02-12</dateofbirth> 
      <major>Math</major> 
      </student> 

      </asdasdasdasd>  

나는이 물건에 아주 새로운 오전. 사과.

<xsd:simpleContent> 
    <xsd:restriction base="xsd:string" /> // closed 
</xsd:restriction>     // closing tag with no starting tag 
</xsd:simpleContent> 

당신은 불필요하게 제한의 시작 태그를 폐쇄하고 : 괜찮은 XML 편집기 또는 XML 도움과 IDE를 사용

답변

0

, 여기서 오류를 발견 한 것입니다. 닫는 태그를 제거하거나 시작 태그의 슬래시를 제거하십시오. 모두 요소가있는 경우에도 마찬가지입니다. 당신은 모두 똑같은 일을하고 있습니다

하지만 또 다른 빛에는 왜 제한이 있습니까? firstName의 유형을 xsd:string에 입력하기 만하면됩니다. 이 경우 제한이 필요한 이유는 무엇입니까? 동일한 패턴을 사용하여 나머지 요소에 대해 동일하게 적용됩니다.

또한 익명의 유형이 많은 것은 바람직하지 않습니다. 외부 발견

다른 문제 선언 생각해

당신이있는 거 학생 id 속성은 학생 요소의 attrubute입니다, 그래서 당신은 simpleType의 내부 simpleContent 필요하지 않습니다 밖에 선택의 여지

 <xsd:attribute name="stuid" type="xsd:integer"/> 
    </xsd:complexType> 
</xsd:choice> 

을 가야한다. 꺼내.

<xsd:element name="major"> 
    <xsd:simpleType> 
     <xsd:simpleContent> 
      <xsd:restriction base="xsd:string"/> 

여기 XSD의 전체 리팩토링 만들기 위해의 IT 유효


<?xml version="1.0"?> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 

    <xsd:annotation> 
     <xsd:documentation> 
      Author: Ankit Gyawalient 
      Creation Date: September 
      8th, 2014 
      Due Date: September 10th, 2014 
      Course: CSC 480 010 
      Professor 
      Name: Dr. Lisa Frye 
      Assignment: 2 
      Filename: hw2xsd.xsd 
      Purpose: To 
      define XML Schema for a university in an external file and use it 
      appropriately. 
     </xsd:documentation> 
    </xsd:annotation> 

    <xsd:element name="asdasdasdasd"> 
     <xsd:complexType> 
      <xsd:choice minOccurs="0" maxOccurs="unbounded"> 
       <xsd:element name="student"> 
        <xsd:complexType> 
         <xsd:choice minOccurs="0" maxOccurs="unbounded"> 
          <xsd:element name="firstname" type="xsd:string" /> 
          <xsd:element name="lastname" type="xsd:string" /> 
          <xsd:element name="email" type="xsd:string" /> 
          <xsd:element name="dateofbirth" type="xsd:date" /> 
          <xsd:element name="major"> 
           <xsd:simpleType> 
            <xsd:restriction base="xsd:string"> 
             <xsd:enumeration value="Computer Science/SD" /> 
             <xsd:enumeration value="Computer Science/IT" /> 
             <xsd:enumeration value="Math" /> 
            </xsd:restriction> 
           </xsd:simpleType> 
          </xsd:element> 
         </xsd:choice> 
         <xsd:attribute name="stuid" type="xsd:integer" /> 
        </xsd:complexType> 
       </xsd:element> 
      </xsd:choice> 
     </xsd:complexType> 
    </xsd:element> 
</xsd:schema> 
그리고 마지막으로 XML 파일에 당신이 월 등이

<dateofbirth>2004-02-32</dateofbirth> 

죄송합니다 그런 일이 없다 32 번째. 적어도 그 xml은 :-)

위의 변경 사항이 적용됩니다. 좋은 참고 가이드가 필요하면 this tutorial을 보시길 바랍니다.