472,805 Members | 4,107 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 2251


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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.