开发者

How do you define an XML schema ID attribute that has a pattern?

This XML documentation seems to say that the ID derived type supports a pattern, but when I try to define one with this code:

      <complexType name="CourseType">
          <attribute name="courseNumber" type="ID">
              <pattern value="[A-Z]{2}(\d{3}).(\d{3})" />
          </attribute>
          <attribute name="numOfCredits" type="university:CourseCredits" />
          <element name="course_name" type="university:MixedName" />
          <element name="course_professor" type="string" />
      </complexType>>

...I get an error in the oXygen XML editor that says The content of 'courseNumber' must match (开发者_StackOverflowannotation?, (simpleType?)). A problem was found starting at: pattern.

Am I defining my schema correctly for that ID attribute?


If you need to restrict built-in simple data type you should create your own simpleType. Use Derivation by Restriction. Try something like this:

<simpleType name='better-ID'>
  <restriction base='ID'>
    <pattern value='(\d{3}).(\d{3})'/>
  </restriction>
</simpleType>

<complexType name="CourseType">
      ...
      <attribute name="courseNumber" type="better-ID"/>
      <attribute name="numOfCredits" type="university:CourseCredits" />
</complexType>

Or you can just embed simpleType:

   <complexType name="CourseType">
          ...
          <attribute name="courseNumber">
              <simpleType>
                  <restriction base='ID'>
                     <pattern value='(\d{3}).(\d{3})'/>
                  </restriction>
              </simpleType>
          </attribute>
          <attribute name="numOfCredits" type="university:CourseCredits" />
    </complexType>

See also @jasso comments below to fix some other errors in your XSD.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜