How to create schema that defines value sets

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    How to create schema that defines value sets

    Can someone provide me with an example of how I define in a schema that I require 25 value sets?

    Say in my XML I have:
    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <linear xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    	<linedata>
    		<line>
    			<rise>253</rise>
    			<run>446</run>
    		</line>
    ...
    </close tags...>
    and I have 25 "line" elements how do I enforce that in my xsd?

    Thanks.
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    minOccurs, maxOccurs. This may be at the element level, or other level such as sequence
    Code:
    <xs:element name="lineData">
    	<xs:complexType>
    		<xs:sequence>
    			<xs:element name="line" maxOccurs="25" minOccurs="25"/>
    		</xs:sequence>
    	</xs:complexType>
    </xs:element>

    Comment

    • RedSon
      Recognized Expert Expert
      • Jan 2007
      • 4980

      #3
      So this statement says that the element named "line" must occur a min and max time of 25 times?

      Thanks I will use that!

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        The feedback I received on the schema is that I should use complex types and put them in the element attribute instead of nesting the complex type.

        Do you have some reference material on how this can be accomplished. I do not understand what this means.

        Comment

        • jkmyoung
          Recognized Expert Top Contributor
          • Mar 2006
          • 2057

          #5
          Basically, use references everywhere to make the schema as flat as possible (1 layer at a time).
          There are 2 ways:
          1. Reference to elements:
          2. Reference to types.

          1. Only referencing elements. Notice use of the ref attribute
          Code:
          <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
          <xs:element name="lineData"> 
              <xs:complexType> 
                  <xs:sequence> 
                      <xs:element ref="line" minOccurs="25" maxOccurs="25"/> 
                  </xs:sequence> 
              </xs:complexType> 
          </xs:element> 
          <xs:element name="line">
              <xs:complexType> 
                  <xs:sequence> 
                      <xs:element ref="item" minOccurs="25" maxOccurs="25"/> 
                  </xs:sequence> 
              </xs:complexType> 
          </xs:element>
          <xs:element name="item" type="xs:string"/>
          </xs:schema>
          Compared to 2. Only referencing types: Notice the use of the type attribute.
          Code:
          <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
          <xs:element name="lineData" type="lineDataType"/> 
          <xs:complexType name="lineDataType">
              <xs:sequence> 
                  <xs:element name="line" minOccurs="25" maxOccurs="25" type="lineType"/> 
              </xs:sequence> 
          </xs:complexType>
          <xs:complexType name="lineType">
              <xs:sequence> 
                  <xs:element name="item" type="xs:string" /> 
              </xs:sequence> 
          </xs:complexType>
          </xs:schema>
          You can also do both 1 and 2, ...which I think is what is being asked

          Comment

          Working...