XML Schema(s): Help Needed

Discussions

XML & Web services: XML Schema(s): Help Needed

  1. XML Schema(s): Help Needed (2 messages)

    I have the following schema, which I believe needs to be fleshed out more to make it more powerful, can someone please help and also point me in the right direction...hopefully once my project gets approved on SourceForge I will be adding this as well as something else I have to the project. Anyeverhow, here is the schema as it stands right now:


    <?xml version="1.0" encoding="utf-8"?>


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


      <xs:element name="student">
      <xs:complexType>
      <xs:sequence>

        <xs:element name="stunum" type="xs:integer" />
        <xs:element name="lastname" type="xs:string" />
        <xs:element name="firstname" type="xs:string" />
        <xs:element name="age" type="xs:integer" />
        <xs:element name="dateborn" type="xs:date" />

      </xs:sequence>
      </xs:complexType>
      </xs:element>


      <xs:element name="address">
      <xs:complexType>
      <xs:sequence>

        <xs:element name="pnum" type="xs:integer" />
        <xs:element name="addnum" type="xs:integer" />
        <xs:element name="street" type="xs:string" />
        <xs:element name="city" type="xs:string" />
        <xs:element name="country" type="xs:string" />
        <xs:element name="poczip" type="xs:string" />

      </xs:sequence>
      </xs:complexType>
      </xs:element>


    </xs:schema>

    If you can make any changes to it, please do...any and all help would be very much appreciated.


    Someone said the following to me as well, although I am having problems understanding what he is implying, probably because he didn't include an example:

    "In your case, it depends on where you're going with this, but I'd consider creating a ComplexType for a "person" and then define your "Student" as an extension of the Person type, adding perhaps the student ID. That way, if you added Instructor, you'd be able to re-use the generalized part of the definition of a person (since Instructors and Students both have some things in common)."

    If I can get this up and running, I will eventually need to be able to easily change some things in it to get it working with a second project that I have on SourceForge.





    Michael Lauzon, Founder
    The Quill Society
    http://www.quillsociety.org/
    mlauzon@quillsociety.org
  2. For some examples you can look at PersonInfo and AddressDetails types described in OASIS Customer Information TC:

    http://www.oasis-open.org/committees/download.php/177/ciq_schemas.zip

    However it's quite likely that schemas from other folks will be either overkill or too weak for your problem domain. So probably you will have to design your own anyway.
  3. The first thing that strikes me about the schema document is that you cannot reuse the types you've defined.

    You may create a document with two elements, each of which has the fields you list in the complex type definition. However, those complex types are essentially anonymous, so you cannot create other elements in other type definitions as being a student or an address.

    If you wish to reuse the type declaration, create a stand-alone, named complex type, and assign the type of the element to be that name, like this:

    ...
      <xs:element name="student" type="this:studentType" />
      <xs:complexType name="studentType">
        <xs:sequence>
          <xs:element name="stunum" type="xs:integer" />
          <xs:element name="lastname" type="xs:string" />
          <xs:element name="firstname" type="xs:string" />
          <xs:element name="age" type="xs:integer" />
          <xs:element name="dateborn" type="xs:date" />
        </xs:sequence>
      </xs:complexType>
    ...

    Notice that the xs:element element is closed off on the first line, and the complex type declaration is its own separate element. Making student a reusable type permits you to compose types from elements of this type. For example, somewhere further in the document...
    ...
      <xs:complexType name="classListType>
        <xs:sequence>
          <xs:element name="className" type="xs:string" />
          <xs:element name="attendee" type="this:studentType" maxOccurs="unbounded" />
          
        </xs:sequence>
      </xs:complexType>
    ...

    These examples assume you've created a namespace alias of "this" to refer to the current document.