Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within XML
Search Coderanch
Advance search
Google search
Register / Login
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
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Liutauras Vilda
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forums:
Web Services Certification (OCEJWSD)
Web Services
XML and Related Technologies
How can I apply Restriction and attribute both for a simple Element in XSD ?
kishan Jaiswal
Greenhorn
Posts: 20
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
This is my XSD, I want to apply length restriction and attribute for contact-no element
<?xml version="1.0" encoding="UTF-8"?> <xs:schema targetNamespace="http://jabbong.com/customers" xmlns:jbc="http://jabbong.com/customers" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" > <xs:element name="customers" type="jbc:customers-type"/> <xs:complexType name="customers-type"> <xs:sequence> <xs:element name="customer" type="jbc:customer-type" minOccurs="1" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:complexType name="customer-type"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="contact-no" type="jbc:attr-contact-type"/> </xs:sequence> <xs:attribute name="customer-type" type="jbc:restr-customer-type"/> </xs:complexType> <!--defining attr for element (contact-no) that has already imposed restriciton for length of contact-no--> <xs:complexType name="attr-contact-type"> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="contact-type" type="jbc:res-contact-type"/> </xs:extension> </xs:simpleContent> </xs:complexType> <!--restriction for attr(contact-type) of element (contact-no)--> <xs:simpleType name="res-contact-type"> <xs:restriction base="xs:string"> <xs:enumeration value="Primary"/> <xs:enumeration value="Secondry"/> </xs:restriction> </xs:simpleType> <!--restriction for attr(customer-type) of complex type(customer-type)--> <xs:simpleType name="restr-customer-type"> <xs:restriction base="xs:string"> <xs:enumeration value="Gold"/> <xs:enumeration value="Platinum"/> </xs:restriction> </xs:simpleType> <!--restriciton for element(contact-no)--> <xs:simpleType name="restr-contact-no-length"> <xs:restriction base="xs:string"> <xs:pattern value="[0-9]{3}-[0-9]{7}"/> <xs:minLength value="11"/> <xs:maxLength value="11"/> </xs:restriction> </xs:simpleType> </xs:schema>
Rob Spoor
Sheriff
Posts: 22821
132
I like...
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Can't you change the base type on line 22?
<xs:complexType name="attr-contact-type"> <xs:simpleContent> <xs:extension base="jbc:restr-contact-no-length"> <xs:attribute name="contact-type" type="jbc:res-contact-type"/> </xs:extension> </xs:simpleContent> </xs:complexType>
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
I don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
XSD Definition For XML
unble to validate xml against schema
unexpected child element xs:element error??
MS Exchange web service: If the 'nillable' attribute is false in the schema, the 'xsi:nil' attribute
Please Help me.- Schema problem
More...