473,761 Members | 9,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1584


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="unbo unded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="phone">
<xs:complexType >
<xs:simpleConte nt>
<xs:extension base="phoneNo">
<xs:attribute name="type" type="homeWork" />
</xs:extension>
</xs:simpleConten t>
</xs:complexType>
</xs:element>

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

<xs:simpleTyp e name="homeWork" >
<xs:restricti on base="xs:string ">
<xs:enumerati on value="home" />
<xs:enumerati on 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
2935
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 defined in a different namespace from the element.
4
1675
by: trexim | last post by:
It seems that .NET does not support xsd:extension and xsd:attribute. What is the alternative? Thanks,
1
2215
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" type="xs:string" /> <xs:element name="tag2" type="xs:string" /> <xs:element name="tag3" type="xs:string" /> .....
2
1228
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 attribute and restrict the input to some range of values. In the example above, I want the enumeration to be restricted to TRUE and MAG. And, I want the valid values the text to be 0 through 359. I seem to be able to get one or the other but not...
4
3594
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# code is, // Create an XSLT transform object XslTransform xslTransform = new XslTransform(); // Load the stylesheet
1
1350
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 parameter the user has entered in the parent element? For example: In the instance document I have the following...
3
3498
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> <description></description> ...
1
9613
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> <subsection name="first"> <!-- subsection contents -->
1
2597
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 example below is the XML structure : <News> <Regional> <Report Region="Asia">
0
9554
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9376
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9988
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9923
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.