Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

XMl : How do I define a data type in my schema

  • 31-03-2009 04:22PM
    #1
    Closed Accounts Posts: 2,696 ✭✭✭


    I'm trying to define a data type for "company" (called myCompany)to only allow 3 positive integers ranging from 000 to 999 - I cannot define the type :( keep getting errors in validation

    Grateful for any assistance :)
    <?xml version="1.0"?>
    <xs:schema xmlns:xs="[URL]http://www.w3.org/2001/XMLSchema[/URL]">
     
     <xs:complexType name="myCompany">
      <xs:restriction base="xs:positiveInteger">
       <xs:length value="3"/>   
      </xs:restriction>
     </xs:complexType>
     <xs:element name="first_name" type="xs:token"/>
     <xs:element name="last_name" type="xs:token"/>
     <xs:element name="house_number" type="xs:positiveInteger"/>
     <xs:element name="street" type="xs:token"/>
     <xs:element name="city" type="xs:token"/>
     <xs:element name="country" type="xs:token"/>
     <xs:element name="age" type="xs:token"/>
     <xs:element name="date_of_birth" type="xs:token"/>
     <xs:element name="employee_id" type="xs:token"/>
     <xs:attribute name="number" type="xs:token"/>
     <xs:attribute name="version" type="xs:string"/>
     <xs:attribute name="date" type="xs:string"/>
     <xs:element name="company" type="xs:myCompany"/>
     <xs:element name="account" type="xs:token"/>
     <xs:element name="sub_account" type="xs:token"/>
     <xs:element name="region" type="xs:token"/>
     <xs:element name="function" type="xs:token"/>
     <xs:element name="cost_centre" type="xs:token"/>
     <xs:element name="intercompany" type="xs:token"/>
     <xs:element name="future" type="xs:token"/>
     
     <xs:element name="amount" type="xs:float"/>
     <xs:element name="currency" type="xs:string"/>
     <xs:element name="expense_type" type="xs:string"/>
     <xs:element name="justification" type="xs:string"/>
     <xs:element name="country_incurred" type="xs:string"/>
     <xs:element name="date_incurred" type="xs:string"/>
     <xs:element name="receipt_required" type="xs:string"/>
     
     
     <xs:element name="expense_reporting">
      <xs:complexType>
       <xs:sequence>
        <xs:element ref="report"/>
       </xs:sequence>
       <xs:attribute ref="version"/>
      </xs:complexType>
     </xs:element>
     <xs:element name="report">
      <xs:complexType>
       <xs:sequence>
        <xs:element ref="owner" />
        <xs:element ref="accounting"/>
        <xs:element ref="expense_report"/>
        <xs:element ref="approver"/>
       </xs:sequence>
       <xs:attribute ref="number"/>
       <xs:attribute ref="date"/>
      </xs:complexType>
     </xs:element>
     <xs:element name="owner">
      <xs:complexType>
       <xs:sequence>
        <xs:element ref="name"/>
        <xs:element ref="address"/>
        <xs:element ref="age"/>
        <xs:element ref="date_of_birth"/>
        <xs:element ref="employee_id"/>
       </xs:sequence>
      </xs:complexType>
     </xs:element>
      <xs:element name="accounting">
      <xs:complexType>
       <xs:sequence>
        <xs:element ref="company"/>
        <xs:element ref="account"/>
        <xs:element ref="sub_account"/>
        <xs:element ref="region"/>
        <xs:element ref="function"/>
        <xs:element ref="cost_centre"/>
        <xs:element ref="intercompany"/>
        <xs:element ref="future"/>
       </xs:sequence>
      </xs:complexType>
     </xs:element>
     <xs:element name="expense_report">
      <xs:complexType>
       <xs:sequence>
        <xs:element ref="expense_lines"/>
       </xs:sequence>
      </xs:complexType>
     </xs:element>
     <xs:element name="approver">
      <xs:complexType>
       <xs:sequence>
        <xs:element ref="employee_id"/>
        <xs:element ref="name"/>    
       </xs:sequence>
      </xs:complexType>
     </xs:element>
      <xs:element name="address">
      <xs:complexType>
       <xs:sequence>
        <xs:element ref="house_number"/>
        <xs:element ref="street"/>
        <xs:element ref="city"/>
        <xs:element ref="country"/>
    
       </xs:sequence>
      </xs:complexType>
     </xs:element>
     
     
     
     <xs:element name="expense_lines">
      <xs:complexType>
       <xs:sequence>
        <!-- COL 31/03/2009 -->
        <!-- 
         minOccurs changed to value "1".
         Previously it had value "15".
         This required there to be at least 15 line elements as 
         children of the expense_lines element.
        -->
        <xs:element ref="line" minOccurs="1" maxOccurs="15"/>
       </xs:sequence>
      </xs:complexType>
     </xs:element>
     <xs:element name="line">
      <xs:complexType>
       <xs:sequence>
        <xs:element ref="amount"/>
        <xs:element ref="currency"/>
        <xs:element ref="expense_type"/>
        <xs:element ref="justification"/>
        <xs:element ref="country_incurred"/>
        <xs:element ref="date_incurred"/>
        <xs:element ref="receipt_required"/>
     
    
       </xs:sequence>
       <!-- COL 31/03/2009 -->
       <!-- 
        Moved from inside xs:sequence.
        An attribute cannot be part of a sequence.
       -->
       <xs:attribute ref="number"/>
      </xs:complexType>
     </xs:element>
     
     <xs:element name="name">
      <xs:complexType>
       <xs:sequence>
        <xs:element ref="first_name"/>
        <xs:element ref="last_name"/>    
       </xs:sequence>
      </xs:complexType>
     </xs:element> 
     
    </xs:schema>
    


Comments

  • Closed Accounts Posts: 2 dolly_no1000


    I think you would need to define the range rather than the "length". Afaik the length attribute is for string types only.

    In this case you would probably need the following:

    <xs:minInclusive value="0"/>
    <xs:maxInclusive value="999"/>


  • Closed Accounts Posts: 2,696 ✭✭✭mark renton


    Ok so I create a simpleType - call it "myInteger"
    but when i link company element to the new type I get a type not declared error in validation
    I'm adding the type in the line after schema url - is this correct?


    <xs:element name="company" type="xs:myInteger"/>
    <xs:simpleType name="myInteger">
     <xs:restriction base="xs:integer">
      <xs:minInclusive value="0"/>
      <xs:maxExclusive value="999"/>
     </xs:restriction>
    </xs:simpleType>
    


  • Closed Accounts Posts: 2,696 ✭✭✭mark renton


    <xs:element name="company" type="xs:myInteger"/>

    schoolboy errer :o xs needs to be removed

    <xs:element name="company" type="myInteger"/>


  • Closed Accounts Posts: 2 dolly_no1000


    hmm right, didn't even see that ;) did that work then?


  • Closed Accounts Posts: 2,696 ✭✭✭mark renton


    Sure did - im on a roll now, thanks


  • Advertisement
Advertisement