Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2005-04-15
3
Medium Priority
?
207 Views
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
0
Comment
Question by:dmehran
  • 2
3 Comments
 
LVL 8

Expert Comment

by:anthonywjones66
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:complexType>
                  <xs:sequence>
                        <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" />
                  </xs:sequence>
            </xs:complexType>
      </xs:element>
</xs:schema>
0
 
LVL 8

Accepted Solution

by:
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:complexType>
               <xs:sequence>
                    <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"  />
               </xs:sequence>
          </xs:complexType>
     </xs:element>

Anthony.
0
 

Author Comment

by:dmehran
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
0

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