xsd - Schema with elements, attributes, and text -


i having trouble getting xml file validate against schema, doesn't have syntax errors according xml editor. trying make course complextype element, keeps telling me can't. xml correct, schema, can't figure out.

here xml:

<?xml version="1.0" encoding="utf-8"?> <courses xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:nonamespaceschemalocation="course_offerings.xsd">    <course id="web225">     <name>web development ii</name>     <offered>spring</offered>     <pre_reqs>web125</pre_reqs>   </course>    <course id="web125">     <name>web development i</name>     <offered>fall</offered>   </course>    <course id="web325">     <name>client-side scripting</name>     <offered>spring</offered>     <offered>fall</offered>     <pre_reqs>web225</pre_reqs>   </course>  </courses> 

and here schema:

<xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema">   <xs:element name="courses">     <xs:complextype>       <xs:sequence>          <xs:element name="course" type="xs:string"/>         <xs:sequence>           <xs:element name="name" type="xs:string"/>           <xs:element name="offered" type="xs:string"/>           <xs:element name="pre_reqs" type="xs:string"/>         </xs:sequence>         </xs:sequence>       <xs:attribute name="id" type="xs:string"/>     </xs:complextype>   </xs:element> </xs:schema> 

since haven't mentioned error getting, i'm providing can observe..

  1. in xml have included statement: xsi:nonamespaceschemalocation="course_offerings.xsd" means default xml schema. need verify name of schema , make sure present in default path.. (same of xml file). otherwise may end seeing error unable locate schema course_offerings.xsd
  2. you have declared <xs:element name="course" type="xs:string"/> string .. should not case.. in xml it's complextype, ie, element having child elements inturn..
    1. all these elements name, offered, pre_reqs should come under complextype
    2. attribute should within scope of complextype..
      otherwise face not 1 multiple errors since definition of element course invalid

refer sample xsd below:

<xs:schema attributeformdefault="unqualified" elementformdefault="qualified" xmlns:xs="http://www.w3.org/2001/xmlschema">   <xs:element name="courses">     <xs:complextype>       <xs:sequence>         <xs:element name="course">           <xs:complextype>             <xs:sequence>               <xs:element name="name" type="xs:string"/>               <xs:element name="offered" type="xs:string"/>               <xs:element name="pre_reqs" type="xs:string"/>             </xs:sequence>             <xs:attribute name="id" type="xs:string" use="required" />           </xs:complextype>         </xs:element>       </xs:sequence>     </xs:complextype>   </xs:element> </xs:schema> 

the above mentioned style hierarchical, there alternative method write schema file.. if understand current consequences , if wish know further let know..

for explanation should good..


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -