473,405 Members | 2,171 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,405 software developers and data experts.

XML schema question, possibly related to xs:any

Hi, here is an XML schema excerpt for an employees details.

<xs:element name="ADDRESS">
<xs:complexType>
<xs:sequence>
<xs:element name="ADDRESSLINE" type="xs:string" maxOccurs="6"/>
<xs:element name="HOUSENUMBER" type="xs:int" minOccurs="1"/>
<xs:element name="POSTCODE" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
What I want is to write an XML schema to validate my XML against and
guarantee that my XML has an <ADDRESS> somewhere in it. Here is an example
of a schema I have written and that works.
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="EMPLOYEE">
<xs:complexType>
<xs:sequence>
<--STUFF FROM ADDRESS COPIED ABOVE -->
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
This schema could be used to validate the following XML
<EMPLOYEE>
<ADDRESS>
<ADDRESSLINE>Downing Street</ADDRESSLINE>
<ADDRESSLINE>London</ADDRESSLINE>
<HOUSENUMBER>10</HOUSENUMBER>
<POSTCODE>SW1A 2AA</POSTCODE>
</ADDRESS>
</EMPLOYEE>
Any although it has taken a while to get this far, it isn't what I really
want. What I want is a schema to confirm there is an ADDRESS portion in the
XML, somewhere. For example I want the following XML to be schema valid
using the same XML schema too.
<EMPLOYEE>
<UK>
<ENGLAND>
<ADDRESS>
<ADDRESSLINE>Downing Street</ADDRESSLINE>
<ADDRESSLINE>London</ADDRESSLINE>
<HOUSENUMBER>10</HOUSENUMBER>
<POSTCODE>SW1A 2AA</POSTCODE>
</ADDRESS>
</ENGLAND>
</UK>
<EMPLOYEE>
And also the following
<EMPLOYEE>
<LEVEL1>
<LEVEL2>
<LEVEL3>
<ADDRESS>
<ADDRESSLINE>somewhere</ADDRESSLINE>
<ADDRESSLINE>somwhere</ADDRESSLINE>
<HOUSENUMBER/>
<POSTCODE>something</POSTCODE>
</ADDRESS>
</LEVEL3>
</LEVEL2>
</LEVEL1>
<EMPLOYEE>
The employee address details could be anywhere in the XML, not just the
examples I have given above. I want my XML schema to confirm that the XML
has an <ADDRESS> node SOMEWHERE in the XML. Does anyone have an idea how
this can be done? According to "XML in a nutshell", I think I should be
looking at xs:any but unfortunately don't (currently) have the skills to put
it all together.

I am also thinking that there might be an XPATH expression like

..//ADDRESS[ADDRESSLINE and HOUSENUMBER and POSTCODE]

somewhere in my XML schema but again I am lacking the required knowledge of
where to put it in.

Any help much appreciated.

Thank you
Clarence


Jul 20 '05 #1
2 1839


Clarence wrote:
The employee address details could be anywhere in the XML, not just the
examples I have given above. I want my XML schema to confirm that the XML
has an <ADDRESS> node SOMEWHERE in the XML. Does anyone have an idea how
this can be done? According to "XML in a nutshell", I think I should be
looking at xs:any but unfortunately don't (currently) have the skills to put
it all together.

I am also thinking that there might be an XPATH expression like

.//ADDRESS[ADDRESSLINE and HOUSENUMBER and POSTCODE]

somewhere in my XML schema but again I am lacking the required knowledge of
where to put it in.


I don't think you can use a W3C XML schema for what you want to express.
Schematron however
http://xml.ascc.net/resource/schematron/schematron.html
lets you specify such restrictions.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
I did not know about "Schematron" Martin. Thank you. I will look at this
later tonight.

For the purposes of the NG and people reading this thread, I note that (from
http://www.oracle.com/technology/tech/xml/index.html) "Schematron" does not
(currently) appear to be a common way of validating XML documents, at least
for people that visit and bother to record their vote on Oracles website.
For example the stats I pulled a few moments ago are:
Which language do you use to validate XML documents?
XML Schema 1435 Votes 65.9%
DTD 500 Votes 23.0%
RelaxNG 37 Votes 1.7%
Schematron 22 Votes 1.0%
Other 23 Votes 1.1%
No comments 160 Votes 7.3%
Total: 2177 votes
Thank you again
Clarence

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:41***********************@newsread4.arcor-online.net...


Clarence wrote:
The employee address details could be anywhere in the XML, not just the
examples I have given above. I want my XML schema to confirm that the XML
has an <ADDRESS> node SOMEWHERE in the XML. Does anyone have an idea how
this can be done? According to "XML in a nutshell", I think I should be
looking at xs:any but unfortunately don't (currently) have the skills to
put it all together.

I am also thinking that there might be an XPATH expression like

.//ADDRESS[ADDRESSLINE and HOUSENUMBER and POSTCODE]

somewhere in my XML schema but again I am lacking the required knowledge
of where to put it in.


I don't think you can use a W3C XML schema for what you want to express.
Schematron however
http://xml.ascc.net/resource/schematron/schematron.html
lets you specify such restrictions.

--

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

Jul 20 '05 #3

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

Similar topics

12
by: lawrence | last post by:
I'm bad at regular expressions. Is this how I would look for any set of characters that go more than 60 characters without a white space? ..{60} Also, does this match a block of PHP in an...
6
by: Michael | last post by:
Hi, I'm looking for any source-code example, showing the use of midi sequencer and midi messages in C++. Which files have to be included ? I wrote a tool in JAVA which has bad timing problems...
1
by: Mike | last post by:
Note: My XML experience to date has (unfortunately) been limited to reading and thinking, rather than implementation. Anyway, I am in the process of trying to figure out the most efficient way...
2
by: Tjerk Wolterink | last post by:
I've a element definition like this: -- <xs:element name="content"> <xs:complexType> <xs:sequence> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:any...
0
by: Nayt Grochowski | last post by:
Does anyone see any problem with the loading a SqlConnection into the System.Web.HttpContextCurrent.Items collection in a Page's Constructor. Then Closing and Disposing of it the OnUnload method? ...
6
by: denis_browne | last post by:
Hi there, I got a tough interview questions lately, and I would like to hear your opinion: An array of N chars is given Write an efficient algorithm to find all the repeating substring with a ...
7
by: BQuin | last post by:
Enter into array, 8 marks, then Call 3 functions greatest Smallest Average Each of these 3 functions will receive as parameters the array of marks as well as the # of elements in the array....
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
agi2029
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,...
0
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...

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.