XML验证错误。我不遵循错误的含义

时间:2011-07-06 02:34:32

标签: xml

错误

File C:\Users\Randy\Documents\XML\case1\jw.xml is not valid.
Value '0:45:44.0Z' is not allowed for attribute 'length'.
    Hint: A valid value would be '14:20:00.0Z'.
    Error location: inventory / album / tracks / @length
    Details
        cvc-datatype-valid.1.2.1: For type definition 'xs:time' the   string '0:45:44.0Z' does not match a literal in the lexical space of built-in type definition 'xs:time'.
        cvc-simple-type.1: For type definition 'xs:time' the string '0:45:44.0Z' is not valid.
        cvc-attribute.3: Value '0:45:44.0Z' of attribute 'length' does not match simple type definition 'xs:time'.
        cvc-complex-type.3.1: The attribute 'length' of complex type '{anonymous}' is not valid.
        cvc-elt.5.2.1: The element <tracks> is not valid with respect to the actual type definition '{anonymous}'.

代码

  <inventory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="music.xsd">
  <album category="Modern" albumID="JW001305">
  <title>Kind of Blue</title>
  <artist>Miles Davis</artist>
  <artist>John Coltrane</artist>
  <tracks length="0:45:44.0Z">
     <track length="0:9:22">So What</track>
     <track length="0:9:46">Freddie Freeloader</track>
     <track length="0:5:37">Blue in Green</track>
     <track length="0:11:33">All Blues</track>
     <track length="0:9:26">Flamenco Sketches</track>
  </tracks>
  </album>
  <album category="Bebop" albumID="JW001312">
  <title>Cookin'</title>
  <artist>Miles Davis</artist>
  <tracks length="0:35:13">
     <track length="0:5:57">My Funny Valentine</track>
     <track length="0:9:53">Blues by Five</track>
     <track length="0:4:22">Airegin</track>
     <track length="0:13:03">Tune-Up</track>
  </tracks>
  </album>
  <album category="Modern" albumID="JW015011">
  <title>Blue Train</title>
  <artist>John Coltrane</artist>
  <tracks length="0:41:54">
     <track length="0:10:39">Blue Train</track>
     <track length="0:9:06">Moment's Notice</track>
     <track length="0:7:11">Locomotion</track>
     <track length="0:7:55">I'm Old Fashioned</track>
     <track length="0:7:03">Lazy Bird</track>
  </tracks>
  </album>
  <album category="Modern" albumID="JW002210">
  <title>Sarah Vaughan</title>
  <artist>Sarah Vaughan</artist>
  <artist>Clifford Brown</artist>
  <tracks length="0:45:30">
     <track length="0:3:58">Lullaby of Birdland</track>
     <track length="0:6:18">April in Paris</track>
     <track length="0:4:10">He's My Guy</track>
     <track length="0:5:49">Jim</track>
     <track length="0:4:41">You're not the Kind</track>
     <track length="0:4:48">Embraceable You</track>
     <track length="0:5:08">I'm Glad there is You</track>
     <track length="0:5:43">September Song</track>
     <track length="0:4:55">It's Crazy</track>
  </tracks>
  </album>
  <album category="Swing" albumID="JW014501">
  <title>Ellington at Newport</title>
  <artist>Duke Ellington</artist>
  <tracks length="1:25:50">
     <track length="0:1:10">The Star Spangled Banner</track>
     <track length="0:3:36">Introduction</track>
     <track length="0:6:21">Black and Tan Fantasy</track>
     <track length="0:3:34">Tea for Two</track>
     <track length="0:4:27">Take the A Train</track>
     <track length="0:8:10">Festival Junction</track>
     <track length="0:7:09">Blues to be There</track>
     <track length="0:5:33">Newport Up</track>
     <track length="0:3:52">Sophisticated Lady</track>
     <track length="0:3:50">Day In, Day Out</track>
     <track length="0:14:20">Dimuendo in Blue/Crescendo in Blue</track>
     <track length="0:0:44">Annoucements, Pandemonium</track>
     <track length="0:3:38">I Got it Bad (and That Ain't Good)</track>
     <track length="0:4:46">Jeep's Blues</track>
     <track length="0:2:49">Tulip or Turnip</track>
     <track length="0:1:08">Riot Prevention</track>
     <track length="0:9:13">Skin Deep</track>
     <track length="0:1:30">Mood Indigo</track>
  </tracks>
  </album>
  <album category="Modern" albumID="JW024181">
  <title>Saxophone Colossus</title>
  <artist>Sonny Rollins</artist>
  <tracks length="0:39:51">
     <track length="0:6:46">St. Thomas</track>
     <track length="0:6:28">You Don't Know What Love Is</track>
     <track length="0:5:13">Strode Rode</track>
     <track length="0:10:06">Moritat</track>
     <track length="0:11:18">Blue 7</track>
  </tracks>
  </album>
  <album category="Bebop" albumID="JW031031">
  <title>The Cole Porter Songbook</title>
  <artist>Charlie Parker</artist>
  <artist>Cole Porter</artist>      
  <tracks length="0:38:56">
     <track length="0:3:24">Easy to Love</track>
     <track length="0:3:10">Begin the Beguine</track>
     <track length="0:2:45">Night and Day</track>
     <track length="0:2:38">What is This Thing Called Love</track>
     <track length="0:3:18">In the Still of the Night</track>
     <track length="0:3:31">I Get a Kick Out of You</track>
     <track length="0:2:39">Just One of Those Things</track>
     <track length="0:3:17">My Heart Belongs to Daddy</track>
     <track length="0:3:31">I've Got You Under My Skin</track>
     <track length="0:5:33">Love for Sale</track>
     <track length="0:5:10">I Love Paris</track>
  </tracks>
  </album>   
  <album category="Modern" albumID="JW061051">
  <title>The Sound of Jazz</title>
  <artist>Billie Holiday</artist>
  <artist>Count Basie</artist>
  <artist>Red Allen</artist>
  <artist>Lester Young</artist>
  <artist>Coleman Hawkins</artist>  
  <tracks length="0:41:41">
     <track length="0:4:46">Wild Man Blues</track>
     <track length="0:4:57">Rosetta</track>
     <track length="0:6:19">Fine and Mellow</track>
     <track length="0:6:53">Blues</track>
     <track length="0:4:27">I Left my Baby</track>
     <track length="0:4:43">The Train and the River</track>
     <track length="0:3:43">Nervous</track>
     <track length="0:5:53">Dickie's Dream</track>
  </tracks>
  </album>
  </inventory>

我错过了xsd文件

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

<xsd:simpleType name="albumIDType">
 <xsd:restriction base="xsd:ID">
    <xsd:pattern value="JW\d{6}" />
 </xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="jazzType">
 <xsd:restriction base="xsd:string">
    <xsd:enumeration value="New Orleans" />
    <xsd:enumeration value="Swing" />
    <xsd:enumeration value="Bebop" />
    <xsd:enumeration value="Modern" />
 </xsd:restriction>
 </xsd:simpleType>

 <xsd:element name="inventory">
 <xsd:complexType>
  <xsd:sequence>
    <xsd:element name="album" minOccurs="1" maxOccurs="unbounded">
      <xsd:complexType>
        <xsd:sequence>
          <xsd:element name="title" type="xsd:string"/>
          <xsd:element name="artist" type="xsd:string" minOccurs="1"  maxOccurs="unbounded" />
          <xsd:element name="tracks">
             <xsd:complexType>
                <xsd:sequence>
                   <xsd:element name="track" minOccurs="1" maxOccurs="unbounded">
                      <xsd:complexType>
                         <xsd:simpleContent>
                            <xsd:extension base="xsd:string">
                               <xsd:attribute name="length" type="xsd:time"  use="optional" />
                            </xsd:extension>
                         </xsd:simpleContent>
                      </xsd:complexType>
                   </xsd:element>
                </xsd:sequence>
                <xsd:attribute name="length" type="xsd:time" use="optional" />
             </xsd:complexType>
          </xsd:element>
        </xsd:sequence>
        <xsd:attribute name="category" type="jazzType" use="required" />
        <xsd:attribute name="albumID" type="albumIDType" use="required" />
      </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>

    </xsd:schema>

1 个答案:

答案 0 :(得分:0)

我找到了xs:time的定义:

<xsd:simpleType name="time">
  <xsd:restriction base="xsd:time">
    <xsd:pattern value="(([01][0-9])|(2[0-3]))(:[0-5][0-9]){2}(\.[0-9]+)?" /> 
    <xsd:annotation>
    <xsd:minInclusive value="00:00:00" /> 
    </xsd:annotation>
  </xsd:restriction>
</xsd:simpleType>

形成pattern元素,似乎小时,分钟和秒部分必须各有两位数。也就是说,您的length值必须各自具有格式

hh:mm:ss

后跟可选时区