Who supports Schema validation of unique

Chip Grandits

Usenet Archive
Joined
Apr 6, 2009
Messages
3
Reaction score
0
I am new to XML and my background is not as a web developer or network services application.

I am investigating whether XML technologies would be appropriate for managing configurations of a federation of simulations in aerospace. Validation of configuration is a major factor that would make me consider adopting XML based technology. Therefore I have gained basic knowledge of XML and XML Schemata as implemented in XSD files.

I am trying to understand who supplies tools that validates XML against schema. The Visual Studio editor seems to do a pretty good job. But when I move on to the idea of creating uniqueness requirements (but not global to the whole document) then I can't find out who to go to.

The example below is, in my belief, a very simple and very contrived to demonstrate a uniqueness requirement in an XSD file, followed by a document that violates that requirement. I simply copied the XSD file for a book, although I created the XML file. Yet none of the tools I have tried indicates an error. Perhaps I don't understand how XML validation is suppose to work. Is it simply the developers responsibility to implement the software to do the validation? It seems like the whole point of a global standard is so that software tool vendors could implement the validation and individual developers who followed the XML could rely on those tools? Perhaps I don't understand the "business model" behind XML? Perhaps I just don't understand how the unique element works?

Perhaps I need to pay for a special high priced tool? Can anyone recommend a source or vendor for such a tool? (I tried going to various websites which claim to do validation of XML against a user supplied XSD, but I just get namespace oriented errors that I don't get through Visual Studio or XML Notepad)

Any assistance or even just leads are greatly appreciated. Thank You, Chip Grandits Advanced Technology Associates.

<xs:schema targetNamespace="http://tempuri.org/myschema/unique" elementFormDefault="qualified" xmlns="http://tempuri.org/myschema/unique" xmlns:mstns="http://tempuri.org/myschema/unique" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="customerOrderType"> <xs:sequence> <xs:element name="item" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="itemID" type="xs:string"/> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="CustomerID" type="xs:string"/> </xs:complexType>

<xs:element name="ordersByCustomer">
<xs:complexType>
<xs:sequence>
<xs:element name="customerOrders" type="customerOrderType" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:unique name="oneCustomerOrdersforEachCustomerID"> <xs:selector xpath="mstns:customerOrders"/> <xs:field xpath="@customerID"/> </xs:unique> </xs:element> </xs:schema>

Now below is a very simple XML instance document that I believe violates the requirement that Customer IDs be unique for the CustomerOrders children of the ordersByCustomer element.

<?xml version="1.0" encoding="utf-8"?>
<ordersByCustomer xmlns="http://tempuri.org/myschema/unique"> <customerOrders CustomerID="1"> <item itemID="442"/> <item itemID="443"/> </customerOrders> <customerOrders CustomerID="2"> <item itemID="444"/> <item itemID="252"/> </customerOrders> <!-- DELIBERATE VIOLATION? repeating CustomerID--> <customerOrders CustomerID="1"> <item itemID="282"/> <item itemID="114"/> </customerOrders> </ordersByCustomer>

But I must confess I can't really tell where the accountability lies. I don't mean legal accountability. But in comparison for C/C++ there is a standard and various vendors and open source organization claim to write a compiler to a standard.
 

P. Lepin

Usenet Archive
Joined
Nov 24, 2007
Messages
35
Reaction score
0
Chip said:
<xs:unique name="oneCustomerOrdersforEachCustomerID">
<xs:selector xpath="mstns:customerOrders"/>
<xs:field xpath="@customerID"/>
</xs:unique>

Now below is a very simple XML instance document that I believe violates the requirement that Customer IDs be unique for the CustomerOrders children of the ordersByCustomer element.

<?xml version="1.0" encoding="utf-8"?>
<ordersByCustomer xmlns="http://tempuri.org/myschema/unique"> <customerOrders CustomerID="1"> <item itemID="442"/> <item itemID="443"/> </customerOrders> <customerOrders CustomerID="2"> <item itemID="444"/> <item itemID="252"/> </customerOrders> <!-- DELIBERATE VIOLATION? repeating CustomerID--> <customerOrders CustomerID="1"> <item itemID="282"/> <item itemID="114"/> </customerOrders> </ordersByCustomer>

XML is case-sensitive. 'CustomerID' is not the same thing as 'customerID'.
 

Chip Grandits

Usenet Archive
Joined
Apr 6, 2009
Messages
3
Reaction score
0
XML is case-sensitive. 'CustomerID' is not the same thing as 'customerID'.
P. Lepin,
Thank you very much for pointing out that error.

I ask the XML community out there, can anyone point out a resource where I can find some example XML Schema code that does not contain errors. Specifically code showing the use of identity constraint features, such as unique, key, and keyref.

The code in question, where P. Lepin found the error was supplied by a small, and perhaps underfunded and understaffed U.S. software company called microsloft. It is in their example code for how to use xsd:unique

Here is the link: http://msdn.microsoft.com/en-us/library/ms256146(VS.85).aspx

I looked around for a source a little more careful that microsloth, I thought perhaps xml.com would be a reputable source. Yet it also supplies erroneous examples (I think, I can't tell because I can't find a validator that I trust). These errors seem even more obvious.
For instance: http://www.xml.com/2002/11/13/examples/Housing2.xsd.txt Here the selector xpath attribute refers to an element that does not exist. I have copied the offending code here (I think they meant for the selector to be HousingUnit)

<key name="UnitIDKey">
<selector xpath="Unit" />
<field xpath="@unitID" />
</key>

I downloaded an evaluation version of Altova XMLSpy, because I came to the conclusion one has to pay money for a properly functioning XML validation tool.

Yet I can put anything in the xpath attribute for selector, hit the F8 key, and and Altova gives me the green check mark saying everything is OK. well I can't type in anything <selector xpath="!@!@!"/> causes a validation error, but <selector xpath="obviouslyNonExistentXpathExpressionSubset"/> is perfectly OK.

Maybe I don't understand what validation means.
It seems reasonable to me that a software tool could tell when an xpath doesn't validly refer to anything (it seems like it should have caught the error P. Lepin caught, where the selector field was "@customerID" instead of "@CustomerID").

I'm having a hard time learning XML, because I learn by example. I can't seem to find any examples that I trust. If anyone can point me to examples that I can trust, that would be very helpful.

Is there a software tool that does the kind of validation I am looking for? If you are a vendor of such a tool please contact me. AltovaSpy is $129, perhaps one needs to pay $1290 for the tool I want??

-Thanks,
Chip Grandits
ATA
 

P. Lepin

Usenet Archive
Joined
Nov 24, 2007
Messages
35
Reaction score
0
Chip said:
I ask the XML community out there, can anyone point out a resource where I can find some example XML Schema code that does not contain errors.

W3C's XML Schema Part 0: Primer SE is a decent reading, if a bit on the chewy side.
I downloaded an evaluation version of Altova XMLSpy, because I came to the conclusion one has to pay money for a properly functioning XML validation tool.

One properly functioning XML validation tool is called
'xmllint'. It's open-source and ubiquitous, since it's a part of libxml2.
Yet I can put anything in the xpath attribute for selector, hit the F8 key, and and Altova gives me the green check mark saying everything is OK. well I can't type in anything <selector xpath="!@!@!"/> causes a validation error, but <selector xpath="obviouslyNonExistentXpathExpressionSubset"/> is perfectly OK.

You're talking nonsense. 'xpath' attribute on 'selector' element can be arbitrarily complex. So can be the rest of your schema. Checking whether your XPath expressions make sense in context of a given schema simply isn't a viable option.
Maybe I don't understand what validation means.

I think you don't. 'Validation' means testing whether a certain XML document complies with an XML Schema (or DTD) you provide. Determining whether your schema makes sense at all is a task best left for humans, since there are some hard problems in the area of formally defining 'makes sense'.
I'm having a hard time learning XML, because I learn by example.

....which is not a valid learning methodology, unless accompanied by attempting to solve problems you come across.

Reading solid introductory materials is a good idea, too. Otherwise you're bound to come back in a couple of weeks asking, 'Why the hell can't I express a certain class of constraints using XML schemata?' (The answer is, 'Because XML schemata are not designed for expressing arbitrary constraints: design from mock-up just doesn't work in this case.')
Is there a software tool that does the kind of validation I am looking for?

I believe the hourly rates on the 'software' tools you're looking for are normally well above $100/hour. Although you might be able to save some if you outsource to Asia or Eastern Europe.
 

Chip Grandits

Usenet Archive
Joined
Apr 6, 2009
Messages
3
Reaction score
0
W3C's XML Schema Part 0: Primer SE is a decent reading, if a bit on the chewy side.

Yes, I was afraid of going to the reference, but I must admit for a standards committee document, its reasonably accessible and does have good example code.
You're talking nonsense. 'xpath' attribute on 'selector' element can be arbitrarily complex. So can be the rest of your schema. Checking whether your XPath expressions make sense in context of a given schema simply isn't a viable option.

I think you don't. 'Validation' means testing whether a certain XML document complies with an XML Schema (or DTD) you provide. Determining whether your schema makes sense at all is a task best left for humans, since there are some hard problems in the area of formally defining 'makes sense'.

O.K. perhaps validation is the wrong word here.
Maybe I should use a term like "reference following"
I agree that any valid value for "A restricted XPath expression" is pretty broad. But my understanding is that a selector for an identity constraint is useful because it refers to something. And I believe that the XPath starts at the element that is the parent of the identity constraint. Now I know that XML and Schema are designed to be extensible with such constructs as xs:any.

But still it seems both possible and useful for a validating tool to "evaluate" an xpath value of a selector in an identity constraint (unique,key or keyref) and then follow that Xpath down from the parent of the identity constraint and see if such a node currently exists. If it doesn't, the validating tool would say something like "your selector does not refer to anything that currently exists in your schema definition"

By the way, after much playing around I found that Altova WILL check the references for you. But you have to hit the validate button when you are looking at your XSD document in Schema view. I don't know if I'd call it a "bug", but I'd say it is a confusing interface "issue". But that's an issue for Altova support and I have contacted them.
...which is not a valid learning methodology, unless accompanied by attempting to solve problems you come across.

Reading solid introductory materials is a good idea, too.

Agreed. O'Reilly has always seemed like a solid publisher. Their book on XML Schema (Eric van der Vlist) is from 2002. Is that too old? Or has the technology been stable for the last 7 years?
Otherwise you're bound to come back in a couple of weeks asking, 'Why the hell can't I express a certain class of constraints using XML schemata?' (The answer is, 'Because XML schemata are not designed for expressing arbitrary constraints: design from mock-up just doesn't work in this case.')

Now that's an interesting and valuable insight!
How 'bout RELAX NG, is that any better?
I believe the hourly rates on the 'software' tools you're looking for are normally well above $100/hour. Although you might be able to save some if you outsource to Asia or Eastern Europe.

Well if we can get 'em to stop developing bogus credit derivative financial instruments for AIG and Lehman Brothers, etc. and actually do something productive for society, I'm happy to see they get well compensated.

But seriously - Thank you very much for your help and insights. I very much appreciate all the help you've already given me.

-Chip Grandits
Advanced Technology Associates
 

P. Lepin

Usenet Archive
Joined
Nov 24, 2007
Messages
35
Reaction score
0
Chip said:
Yes, I was afraid of going to the reference, but I must admit for a standards committee document, its reasonably accessible and does have good example code.

Well, it's a primer and clearly written as such. Good thing W3C bothered to come up with it, too, since I know of no other online introductory materials of even comparable quality.
I think you don't. 'Validation' means testing whether a certain XML document complies with an XML Schema (or DTD) you provide. Determining whether your schema makes sense at all is a task best left for humans, since there are some hard problems in the area of formally defining 'makes sense'.
[...]

But still it seems both possible and useful for a validating tool to "evaluate" an xpath value of a selector in an identity constraint (unique,key or keyref) and then follow that Xpath down from the parent of the identity constraint and see if such a node currently exists. If it doesn't, the validating tool would say something like "your selector does not refer to anything that currently exists in your schema definition"

By the way, after much playing around I found that Altova WILL check the references for you. But you have to hit the validate button when you are looking at your XSD document in Schema view. I don't know if I'd call it a "bug", but I'd say it is a confusing interface "issue". But that's an issue for Altova support and I have contacted them.

Good feature I suppose, but I'd warn you not to rely on it. This
*is* a hard problem, and I wouldn't trust a tool to get it right (especially Altova's tool -- but I'm prejudiced, their XML Spy has horrible track record where it comes to standard compliance).
Agreed. O'Reilly has always seemed like a solid publisher. Their book on XML Schema (Eric van der Vlist) is from 2002. Is that too old? Or has the technology been stable for the last 7 years?

Haven't read it myself, but you should be fine with it. XML Schema 1.0 is from 2001, and 1.1 is still a WD.
Now that's an interesting and valuable insight!
How 'bout RELAX NG, is that any better?

I haven't touched RELAX NG in a really long while, but from what I recall it's *different*, not better. There are some things RELAX NG schemata can do that W3C XML schemata can't, and vice versa. Another thing for you to consider would be Schematron constraint checker. You can slap Schematron constraints on top of RELAX NG or W3C schema, and it helps some for sure.

But if you want in-depth info on either RELAX NG or Schematron, you'd have to ask someone else on the group or do your own research, since I'm very rusty with both of those.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top