Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2005-04-15
Medium Priority
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
  • 2

Expert Comment

ID: 13794897
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified"
      xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:mstns="http://tempuri.org/XMLSchema.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <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" />

Accepted Solution

anthonywjones66 earned 1400 total points
ID: 13794924
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

ID: 13798966
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

810 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