473,378 Members | 1,438 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,378 software developers and data experts.

XML schema validation question restricting"attributes" count

Hi, I have some sample XML and an XSD below I have written.

The XSD almost does what I want. What I need is some way of enforcing
that AT LEAST TWO of the attributes "TestAttribute" are "X".

Can this be done and if so how?
Thank you
Victor

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="TestXML">
<xs:complexType>
<xs:sequence minOccurs="2" maxOccurs="4">
<xs:element name="TestElement">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="TestAttribute" type="xs:string"
use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML that is valid, 2 TestAttribute="X" (2 satisfies "AT LEAST TWO")
================================================== =================

<?xml version="1.0" encoding="UTF-8"?>
<TestXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\test.xsd">
<TestElement TestAttribute="3">Mark</TestElement>
<TestElement TestAttribute="5">Peter</TestElement>
<TestElement TestAttribute="X">John</TestElement>
<TestElement TestAttribute="X">Luke</TestElement>
</TestXML>
XML that is valid, 3 TestAttribute="X" (3 satisfies "AT LEAST TWO")
================================================== =================

<?xml version="1.0" encoding="UTF-8"?>
<TestXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\test.xsd">
<TestElement TestAttribute="3">Mark</TestElement>
<TestElement TestAttribute="X">Peter</TestElement>
<TestElement TestAttribute="X">John</TestElement>
<TestElement TestAttribute="X">Luke</TestElement>
</TestXML>
XML that does not conform to the modified schema above
1 TestAttribute="X" (1 DOES NOT satisfy "AT LEAST TWO")
================================================== =================

<?xml version="1.0" encoding="UTF-8"?>
<TestXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\test.xsd">
<TestElement TestAttribute="3">Mark</TestElement>
<TestElement TestAttribute="5">Peter</TestElement>
<TestElement TestAttribute="7">John</TestElement>
<TestElement TestAttribute="X">Luke</TestElement>
</TestXML>
Jul 20 '05 #1
3 2277


Victor wrote:
The XSD almost does what I want. What I need is some way of enforcing
that AT LEAST TWO of the attributes "TestAttribute" are "X".

Can this be done and if so how?


The W3C schema language allows uniqueness and key constraints but none
of those can in my view express the constraint of at least two
attributes having a certain value.
--

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

Jul 20 '05 #2
I see. I couldn't not find anything on the W3 website either.

I can redesign my application to use an XML schema that dictated ONE AND
ONLY ONE of the "TestElement" had an attribute that was "X" (ie if there
existed more than one "TestElement" in "TestXML" with an attribute "X" then
the XML was invalid, if there existed no "TestElement" in "TestXML" with an
attribute "X" then the XML it would be invalid).

Can this done?
By the way, thank you very much for putting me on the right track the other
day.
Victor
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:40********@olaf.komtel.net...


Victor wrote:
The XSD almost does what I want. What I need is some way of enforcing
that AT LEAST TWO of the attributes "TestAttribute" are "X".

Can this be done and if so how?


The W3C schema language allows uniqueness and key constraints but none
of those can in my view express the constraint of at least two
attributes having a certain value.
--

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


Jul 20 '05 #3
I'm thinking along the lines of

<xs:field xpath="count(//.@TestAttribute="X")=1/>

but I just can't get it to work properly yet.

Thanks
Victor
"John Smith" <Jo**********@hotmail.com> wrote in message
news:10****************@iris.uk.clara.net...
I see. I couldn't not find anything on the W3 website either.

I can redesign my application to use an XML schema that dictated ONE AND
ONLY ONE of the "TestElement" had an attribute that was "X" (ie if there
existed more than one "TestElement" in "TestXML" with an attribute "X" then the XML was invalid, if there existed no "TestElement" in "TestXML" with an attribute "X" then the XML it would be invalid).

Can this done?
By the way, thank you very much for putting me on the right track the other day.
Victor
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:40********@olaf.komtel.net...


Victor wrote:
The XSD almost does what I want. What I need is some way of enforcing
that AT LEAST TWO of the attributes "TestAttribute" are "X".

Can this be done and if so how?


The W3C schema language allows uniqueness and key constraints but none
of those can in my view express the constraint of at least two
attributes having a certain value.
--

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


Jul 20 '05 #4

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

Similar topics

5
by: Paul Miller | last post by:
We've run into minidom's inabilty to handle large (20+MB) XML files, and need a replacement that can handle it. Unfortunately, we're pretty dependent on a DOM, so a pulldom or SAX replacement is...
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...
5
by: Ralf Wahner | last post by:
Dear Masters of XML As I'm new to XML Schema I dare to ask a possibly recurring question: Given an element <elem> with two attributes @a and @b. The attributes are bound by the condition, that...
2
by: Marek | last post by:
Actually, the very first question I should ask is "does it make sense at all?". For 2 days I've been trying to generate C# classes using XML schema and xsd.exe tool. So far the results are not...
12
by: Stefano | last post by:
Hi all, what is the correct use of the "default" attribute in XML Schema? For example: <xs:element name="myProperty" type="xs:string" default="myDefaultValue"/> What can I do with it? What...
5
by: CindyRob | last post by:
Using .NET framework 1.1 SP1, .NET framework SDK 1.1 SP1, Visual Studio .NET 2003, hotfixes 892202 and 823639. I create a proxy class using wsdl.exe, and in the serialized XML request, I see...
7
by: tah | last post by:
Hey, Can someone please clarify, confirm, or set me straight on my understanding of a standalone="yes" attribute in the xml version element? I assume it means that the xml document containing it...
4
by: Sean LeBlanc | last post by:
I'm trying to discern whether XML Schema can do something like this: Supposing the element has two attributes, id and value. Now, if id = one value, say "number" vs. another value, say,...
7
by: Christian Hackl | last post by:
Hi everyone, I've got a question about what makes the "img" element's width/height attributes valid HTML or XHTML. First of all, this is a rather theoretical question, but digging through the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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
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?
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...

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.