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.

Hi,
I have xml file like this
Code:
<?xml version="1.0" encoding="UTF-8"?>
<SWService xsi:schemaLocation="file:///V:/main/service.xsd"  
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://axis.com/service"  
   Version="1.0">

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

<Service Id="MEC3" Name="MEC3 request">
  <Description>Choose request to use </Description>
  <ServiceCustomer>
    <SW Service="CTRL" Path="/work/service.xml"/>
  </ServiceCustomer>
 <ServiceSupplier>
  <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"/>
 </ServiceSupplier>
</Service>
</SWService>
I cant understand how to represent ServiceState tag in xsd
Code:
  <ServiceState>---</ServiceState>
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
Code:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wmh="http://www.wmhelp.com/2003/eGenerator" elementFormDefault="qualified">

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

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

  <xs:complexType name="ServiceType">
  <xs:complexContent>
  <xs:extension base="IdType">
  <xs:sequence>
    <xs:element name="Description" type="xs:string" maxOccurs="1" minOccurs="0"/>
    <xs:element name="ServiceCustomer" type="ServiceCustomerType" maxOccurs="1"
    minOccurs="0"/>
    <xs:element name="ServiceSupplier" type="ServiceSupplierType" maxOccurs="1"  
    minOccurs="0"/>
  </xs:sequence>
  <xs:attribute name="Name" type="xs:string" use="required"/>
  </xs:extension>
  </xs:complexContent>
   </xs:complexType>
   ---------------------------
   --------------------
  </xs:schema>
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