473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Can I restrict both attribute contents and element contents in schema


I would like to have the following XML:
<phone type="work">555-123-1234</phone>
<phone type="home">555-123-4321</phone>

Is it possible to write a schema to restrict the contents of
the type attribute to be enumerated ("work" or "home") AND restrict the
contents of the <phone> element to match the pattern \d\d\d-\d\d\d-\d\d\d\d
?

I know how to do one or the other, but I haven't figured out a way
to do both. It seems that the pattern restriction can only be
applied to a simple type, but a simple type cannot have attributes. So
what I want to do may not be possible. Is this correct?

--
Don Adams
Jul 20 '05 #1
1 1543


Don Adams wrote:
I would like to have the following XML:
<phone type="work">555-123-1234</phone>
<phone type="home">555-123-4321</phone>

Is it possible to write a schema to restrict the contents of
the type attribute to be enumerated ("work" or "home") AND restrict the
contents of the <phone> element to match the pattern \d\d\d-\d\d\d-\d\d\d\d
?

I know how to do one or the other, but I haven't figured out a way
to do both. It seems that the pattern restriction can only be
applied to a simple type, but a simple type cannot have attributes. So
what I want to do may not be possible. Is this correct?

Here is a schema that defines your element phone and an element root to
contain a sequence of phone elements

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="phone" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="phone">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="phoneNo">
<xs:attribute name="type" type="homeWork" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>

<xs:simpleType name="phoneNo">
<xs:restriction base="xs:string">
<xs:pattern value="\d{3}-\d{3}-\d{4}" />
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="homeWork">
<xs:restriction base="xs:string">
<xs:enumeration value="home" />
<xs:enumeration value="work" />
</xs:restriction>
</xs:simpleType>

</xs:schema>
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Lénaïc Huard | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, I've some namespace problems when defining default values for attributes. My problem seems to come from the fact that the attributes are...
4
by: trexim | last post by:
It seems that .NET does not support xsd:extension and xsd:attribute. What is the alternative? Thanks,
1
by: Maksim | last post by:
Trying to find out a way how to restrict value of the element by name of an element, it might be not even possible, but anyhow. Let's consider following snippet: <xs:element name="tag1"...
2
by: bogus1one | last post by:
To all you XML experts, let's say I have the following in an XML doc: <heading units="TRUE">55</heading> I would like to develop a schema that will both provide for an enumeration for the...
4
by: David S. Alexander | last post by:
I am trying to transform XML to XML using an XSLT in C#, but the root node of my XML is not being matched by the XSLT if it has an xmlns attribute. Am I handling my namespaces incorrectly? My C#...
1
by: da_pander | last post by:
Hi, Can anyone tell me if it is possible to create a XSD schema document that will only allow certain elements to be displayed as available within the instance document depending on say a...
3
by: Jon | last post by:
I have an xml document like so... <?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:ng="http://newsgator.com/schema/extensions"> <channel> <title></title> <link></link>...
1
by: Asko Telinen | last post by:
Hi all. I´m a bit newbie writing xml schemas. Is it possible to define xml element that must have unique attribute values in same level. For example if i have a xml - document: <list>...
1
by: john20 | last post by:
Hi All, I have an XMl structure and i am creating XML Schema document for validating xml document. What i want that for a particular element it should not allow same attribute name. for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.