• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

XML Schema design help

 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Is it possible to restrict the data in XML to a limited value by using Schema..
To be clear,
For example..please look the below XSD and XML.
file:Members.XSD
<xsd:element name="Members">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Member" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:sequence>
<xsd:complexType>
</xsd:element>
file:Members.XML

<Members>
<Member><title>Mr</title><name>Balaji</name></Member>
<Member><title>Dr</title><name>Rangaraj</name></Member>
</Members>

Now is it possible via Schema to restrict the data in child element <title> to be either
Mr or Mrs or Ms or Dr.

Or is it possible to refer to external XML file which has the these value like
file:titles.XML
<titles>
<title>Mr</title>
<title>Mrs</title>
<title>Dr</title>
<title>Ms</title>
</titles>
and restrict the Members.XML child element <title> to have only datas in titles.XML.

Sorry for this long post.Please give me some tips or any URL to refer for this particular reqt.

Regards
Balaji
 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use Enumeration facet to constrain the values of <title> element.
The enumeration can have the values "Mr, Mrs, Dr" etc.
<xsd:simpleType name="title">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Mr"/>
<xsd:enumeration value="Mrs"/>
<xsd:enumeration value="Dr"/>
<xsd:enumeration value="Ms"/>
</xsd:restriction>
</xsd:simpleType>
HTH,
Hema
 
Balaji Loganathan
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Hema,
Thanks a lot for your help.Its worked for me.
Could please tell me whether its possible to refer to external XML file which has the these value like file:titles.XML( Please refer my previous question).
Because Some time I may have to store large datas in enumeration like coutries list in that case the total XSD file may grow larger and larger. Please suggest.
Thanks again.
Regards
 
Balaji Loganathan
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here the solution I found for mz second question,please comment if its a wrong approach.
Thanks Menon Hema ,you made me think.
<?xml version="1.0"?>
<xsd:schema targetNamespace="http://www.hello.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.hello.org" elementFormDefault="qualified">
<xsd:include schemaLocation="toshowlist.xsd"/>
<xsd:element name="Root">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Value" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Value_type"/>
<xsd:element name="Amount" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
*///////////////
<?xml version="1.0"?>
<!-- edited with XML Spy v4.1 U (http://www.xmlspy.com) by () -->
<xsd:schema targetNamespace="http://www.hello.org" xmlns="http://www.hello.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xsd:element name="Value_type" type="list">
</xsd:element>
<xsd:simpleType name="list">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="abcd"/>
<xsd:enumeration value="efgh"/>
<xsd:enumeration value="saas"/>
<xsd:enumeration value="sasas"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
*////////////////////////
<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns="http://www.hello.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.hello.org
toshow.xsd">
<Value>
<Value_type>abcd</Value_type>
<Amount>String</Amount>
</Value>
</Root>
Regards
Balaji
reply
    Bookmark Topic Watch Topic
  • New Topic