Hi, I have a not simple problem.
I want the following XML to be schema valid
<PopulationDemo graphic>
<PersonName>J oe Blogs</PersonName>
<Age>2</Age>
<Category>bab y</Category>
</PopulationDemog raphic>
And I want the following XML to be schema invalid
<PopulationDemo graphic>
<PersonName>J oe Blogs</PersonName>
<Age>2</Age>
<Category>teena ger</Category>
</PopulationDemog raphic>
I can see how to create the restriction of "baby", "todler",
"teenager" and "pensioner" for my element "Category". I can see how to
restrict the ages to one of "1", "2", "3" ... "110" using similar
code. But I can't work out how to say in the schema
if "Category" = "baby" then valid ages must be "1", "2"
if "Category" = "todler" then valid ages must be "2", "3", "4" and "5"
if "Category" = "teenager" then valid ages must be "13", "14", "15",
"16", "17", "18" and "19"
if "Category" = "pensioner" then valid ages must be "65", "66" ....
"110"
Here is my schema now
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Populatio nDemographic">
<xs:complexType >
<xs:sequence>
<xs:element name="PersonNam e" type="xs:string "/>
<xs:element name="Age" type="ages"/>
<xs:element name="Category" type="category"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleTyp e name="category" >
<xs:restricti on base="xs:string ">
<xs:enumerati on value="baby"/>
<xs:enumerati on value="todler"/>
<xs:enumerati on value="teenager "/>
<xs:enumerati on value="pensione r"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleTyp e name="ages">
<xs:restricti on base="xs:string ">
<xs:enumerati on value="1"/>
<xs:enumerati on value="2"/>
<xs:enumerati on value="3"/>
<xs:enumerati on value="4"/>
<!-- all the others up to 110 -->
</xs:restriction>
</xs:simpleType>
</xs:schema>
How can I do this? I have a feeling there is going to be an xpath and
keyref here somewhere but don't have the skills yet to know this for
certain or write the code (I am using xmlspy and the book xml in a
nutshell).
If anyone has an online reference, a pseudo code snippet, or help me
out with extending above for say todlers (I will do the rest) I would
really appreciate it.
This is my first post to newsgroup so sorry to have to ask a nasty
question like this without contributing anything first.
Thank you
Bruce 1 1944
On 16 Feb, 15:23, brucepickford.. .@hotmail.co.uk wrote:
Hi, I have a not simple problem.
I want the following XML to be schema valid
<PopulationDemo graphic>
<PersonName>J oe Blogs</PersonName>
<Age>2</Age>
<Category>bab y</Category>
</PopulationDemog raphic>
And I want the following XML to be schema invalid
<PopulationDemo graphic>
<PersonName>J oe Blogs</PersonName>
<Age>2</Age>
<Category>teena ger</Category>
</PopulationDemog raphic>
I can see how to create the restriction of "baby", "todler",
"teenager" and "pensioner" for my element "Category". I can see how to
restrict the ages to one of "1", "2", "3" ... "110" using similar
code. But I can't work out how to say in the schema
if "Category" = "baby" then valid ages must be "1", "2"
if "Category" = "todler" then valid ages must be "2", "3", "4" and "5"
if "Category" = "teenager" then valid ages must be "13", "14", "15",
"16", "17", "18" and "19"
if "Category" = "pensioner" then valid ages must be "65", "66" ....
"110"
Here is my schema now
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Populatio nDemographic">
<xs:complexType >
<xs:sequence>
<xs:element name="PersonNam e" type="xs:string "/>
<xs:element name="Age" type="ages"/>
<xs:element name="Category" type="category"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleTyp e name="category" >
<xs:restricti on base="xs:string ">
<xs:enumerati on value="baby"/>
<xs:enumerati on value="todler"/>
<xs:enumerati on value="teenager "/>
<xs:enumerati on value="pensione r"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleTyp e name="ages">
<xs:restricti on base="xs:string ">
<xs:enumerati on value="1"/>
<xs:enumerati on value="2"/>
<xs:enumerati on value="3"/>
<xs:enumerati on value="4"/>
<!-- all the others up to 110 -->
</xs:restriction>
</xs:simpleType>
</xs:schema>
How can I do this? I have a feeling there is going to be an xpath and
keyref here somewhere but don't have the skills yet to know this for
certain or write the code (I am using xmlspy and the book xml in a
nutshell).
If anyone has an online reference, a pseudo code snippet, or help me
out with extending above for say todlers (I will do the rest) I would
really appreciate it.
This is my first post to newsgroup so sorry to have to ask a nasty
question like this without contributing anything first.
Thank you
Bruce
Hi Bruce,
Firstly I suggest you make your 'age' type similar to
<xs:simpleTyp e name="ages">
<xs:restricti on base="xs:int">
<xs:minInclusiv e value="0"/>
<xs:maxInclusiv e value="110"/>
</xs:restriction>
</xs:simpleType>
In terms of checking your categories are the right age range,
currently this is not possible in XSD alone. The current approach to
such problems seems to be to suggest using Schematron embedded in the
schema to specify the constraints ( http://www.schematron.com/). The
current version of XSD 1.1 being developed is likely to allow such
constraints to be specified, but there is no fixed date for when it
will be released yet.
It might just be easier to check it at the application level!
HTH,
Pete.
=============== =============== ===============
Pete Cordell
Tech-Know-Ware Ltd
for XML to C++ data binding visit http://www.tech-know-ware.com/lmx
(or http://www.xml2cpp.com)
=============== =============== =============== This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: linkspeed |
last post by:
Hi, I tried following element definition in MSXML 4.0
<xsd:element name="Identifier">
<xsd:simpleType>
<xsd:restriction base="xsd:token">
<xsd:pattern value=".*"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
It can validate XML text like: <Identifier>abbbb</Identifier>
|
by: Andrey Brozhko |
last post by:
Hi
I need to represent custom type system (ints, bytes, chars, enums,
bitmasks, arrays and some other types) in xml. It is easy to see how to
represent enums in xml (using xs:enumeration), the same is true for
numeric types. Even arrays have an obvious description in schema:
<complexType name="IntArray">
<sequence>
<element name="item" type="int" minOccurs="0" maxOccurs="unbounded"/>
|
by: Derek |
last post by:
I am writing a web application for job seekers, and am adding a
section that allows administrators to upload jobs to the system via
xml. I have used an xml schema to validate the xml they upload. The
website runs on IIS5 using classic ASP, and the xml validation is done
in a .NET component written in C# that is registered for COM interop
on the webserver.
I have a test application to test the .NET component, and that
application does...
|
by: Codex Twin |
last post by:
hello group:
The following is a fragment from a schema which defines the
EWethnicCategoryStructure type. As you can see, its type is defined by the
SimpleType enumeration EWethnicCategoryType.
EWethnicCategoryType is defined as a union with the CommonEthnicCategoryType
SimpleType enumeration.
Now when I use the XSD tool to create a C# class of this schema, the
resulting code does not include the SelectedEthnicCategory enumeration.
|
by: bibsoconner |
last post by:
Hi,
I hope someone can please help me. I'm having a lot of trouble with
schema files in .NET. I have produced a very simple example that uses
"include" to include other schema files. It all works with SPY, but
when I pick "Validate Schema" from the .NET 2003 menu, it fails with
message:
"Type XType is not declared." As I hinted at in my subject line, I
suspect that it has to do with including another schema multiple times.
| |
by: ciaran.mchale |
last post by:
Hi folks,
I downloaded the binary version of Xerces C++ 2.7.0 for Windows and am
using it to help me get up to speed with XML and XML Schema. So please
excuse me if this is a "novice" question.
In the samples/data directory, I ran the following command for all the
files:
DOMPrint -n -s -f -v=always <filename>
|
by: tankbattle |
last post by:
That is, what's the difference between
<complexType name="Address" final="restriction">
<sequence>
<element name="name" type="string"/>
<element name="street" type="string"/>
<element name="city" type="string"/>
</sequence>
</complexType>
and
<complexType name="Address" block="restriction">
|
by: Thea |
last post by:
Hi
I am trying to use datatypes defined in xml file to check correctness
of input parameter values
To define needed datatypes following schema.xml file was created:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:pd="uri:myUri.com">
<xsd:simpleType name="pd:width">
|
by: BorisBoshond |
last post by:
Hi all,
Hope someone is able and willing to help me with following problem.
I received a xsd file from another company, our company i supposed to return xml based on that xsd.
Problem is that I don't really understand how these namespace work in xml.
(I am however aware of what problems namespaces solve)
I'm not even sure if the provided xsd is 'common' practice, although it validates correctly.
So I'll describe exactly what I've...
|
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...
|
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,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |