View Single Post
Old January 4th, 2012, 09:50 AM
pavanibiji pavanibiji is offline
Authorized User
Points: 82, Level: 1
Points: 82, Level: 1 Points: 82, Level: 1 Points: 82, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Nov 2011
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to declare some elements as optional in xsd.

I have xml file like this
<?xml version="1.0" encoding="UTF-8"?>
<SWService xsi:schemaLocation="file:///V:/main/service.xsd"  
  xmlns:xsi="" xmlns=""  

 <Service Id="CTRL" Name="Controlunit">
  <Description>Provides some information </Description>
    <State Id="NOM">
        <SupplierState SN="1" Id="NOM"/>
        <SupplierState SN="2" Id="NOM"/>
   <SW Service="EEC3" Path="/work/service.xml" SN="1"/>
   <SW Service="PCTRL" Path="/work/service1.xml" SN="2"/> 

<Service Id="MEC3" Name="MEC3 request">
  <Description>Choose request to use </Description>
    <SW Service="CTRL" Path="/work/service.xml"/>
  <SW Service="INJ" Path="/work/service.xml" SN="2"/>
  <SW Service="P3" Path="/work/service1.xml" SN="3"/>
  <SW Service="NOS" Path="/work/service2.xml" SN="1"/>
I cant understand how to represent ServiceState tag in xsd
some times this element is there but some times in some service nodes there is no ServiceState element , how to represent it in xsd. I represented remaining elements as like below
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs=""
xmlns:wmh="" elementFormDefault="qualified">

 <xs:element name="SWService" type="SWServiceType"/>

  <xs:complexType name="SWServiceType"> 
  <xs:element name="Service" type="ServiceType" minOccurs="0" maxOccurs="unbounded"/>

  <xs:complexType name="ServiceType">
  <xs:extension base="IdType">
    <xs:element name="Description" type="xs:string" maxOccurs="1" minOccurs="0"/>
    <xs:element name="ServiceCustomer" type="ServiceCustomerType" maxOccurs="1"
    <xs:element name="ServiceSupplier" type="ServiceSupplierType" maxOccurs="1"  
  <xs:attribute name="Name" type="xs:string" use="required"/>
but I am confusing to represent ServiceState element because some times present and some times not present , how to declare this element as optional.

thanks in advance