New to XSD and XML, need to define certain elements as required and the other ones as optional

Posted on 2005-04-15
Last Modified: 2013-11-19
Hi, I am very new to XML Schema and I have the following question. Lets say I am trying to create a Schema for a 'Person' whose information include (SSN, name, address, phone). SSN and name are required with only 1 occurrence of them, whereas address and phone are optional with 0 or 1 occurrences. Could someone show me a simple example of how this is done.

thanks in advance
Question by:dmehran
    LVL 8

    Expert Comment

    <?xml version="1.0" encoding="utf-8" ?>
    <xs:schema targetNamespace="" elementFormDefault="qualified"
          xmlns="" xmlns:mstns="" xmlns:xs="">
          <xs:element name="Person">
                            <xs:element name="SSN" type="xs:string" minOccurs="1" maxOccurs="1" />
                            <xs:element name="address" type="xs:string" minOccurs="0" maxOccurs="1" />
                            <xs:element name="phone" type="xs:string" minOccurs="0" maxOccurs="1" />
    LVL 8

    Accepted Solution

    The maxOccurs are there to be explicit but since maxOccurs and miOccurs both default to 1 this can simplyfied to:-

         <xs:element name="Person">
                        <xs:element name="SSN" type="xs:string"  />
                        <xs:element name="address" type="xs:string" minOccurs="0" />
                        <xs:element name="phone" type="xs:string" minOccurs="0"  />


    Author Comment

    cool, I figured that the answer must be simple but I was a bit confused since i wasn't sure whether I needed to use attributes in order to define the elements as qualified or optional.

    thanka again

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System ( introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now