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

keyref validation problems

I'm trying to figure out exactly what's going wrong with an xpath
keyref validation scenario.

In brief, I have something like the following in my xsd:
<xs:schema>
<xs:complexType name="topLevelContainer">

<!-- define an element -->
<xs:complexType name="element">
...
<xs:attribute name="id" type="xs:int" use="required"/>
</xs:complexType>

<!-- instance one, simple list -->
<xs:element name="instanceOne" minOccurs="0">
<xs:sequecne>
<xs:element name="elementDescription" type="element"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<!-- instance two, an inner, heterogenous list -->
<xs:complexType name="instanceTwo" type="anotherType">
<xs:element name="elementList">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:complexType name="fullElement"
type="elementType"/>
<xs:complexType name="elementRef" type="xs:int"/>
</xs:choice>
</xs:complexType>
</xs:sequence>

<!-- constraints -->
<!-- key points to the id attribute of instanceOne type -->
<xs:key name="elementKey">
<xs:selector xpath="instanceOne/elementDescription"/>
<xs:field xpath="@id">
</xs:key>

<!-- keyref points to more-deeply nested instanceTwo type -->
<xs:keyref name="elementRef" refer="elementKey">
<xs:selector xpath="instanceTwo/elementList/elementRef"/>
<xs:field xpath="."/>
</xs:keyref>

</xs:complexType> <!-- end top-level container -->
</xs:schema>

In short, what I am trying to do is ensure that the references from
within the instanceTwo type point to elements within the instanceOne
type. But what I'm not able to figure out is how to enforce that the
instanceTwo type contain references to fully described elements in
instanceOne only. For some reason, a file will validate when the
references out of instanceTwo refer to elementDescriptions from other
instanceTwos in the file.

I'm suspicious that the xpath comparison will never return false for
some reason related to datatype. (My xml editor seems to suggest that
the xpath expressions are returning the appropriate values.)

???

Apr 27 '06 #1
4 1638
Hi,

Your schema has quite a large number of structural problems - keys
within complex types instead of elements, complex types with type
attributes, complex types directly within choice groups, etc.

I'm assuming this is because you cut down the example to be concise, but
it makes it awfully hard to debug the problem when it's not a valid
schema.

Your general approach looks right to me. It could be a namespace issue
- if you're using a target namespace, you must prefix all your element
names in your XPaths. It could also be a problem with your XML Editor,
since some of them are buggy when it comes to identity constraints.

Otherwise, you could post the real schema and we could take a look at
it.

Hope that helps,
Priscilla

----------------------------------
Priscilla Walmsley
Author, Definitive XML Schema
Definitive XQuery
http://www.datypic.com
----------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Apr 27 '06 #2
Hi,

The xsd is available at
http://psidev.sourceforge.net/mi/rel25/src/MIF25.xsd . XML Spy
documentation is available at
http://psidev.sourceforge.net/mi/rel25/doc/ . As you mentioned it is
quite complicated and likely to have some structural problems, and I've
made some minor revisions to the original for purposes of the example
as I've analyzed the problem.

Thanks...

Apr 27 '06 #3
Hi,

The most obvious thing I notice is that you are using a target
namespace, but you are not prefixing the element names in your paths.
XPath expressions are not affected by default namespace declarations, so
you will need to declare a prefix for the default namespace, e.g.

xmlns:xyz="net:sf:psidev:mi"

Then prefix all the element names in your XPaths, e.g.

<xs:selector xpath="xyz:experimentList/xyz:experimentDescription" />

Hope that helps,
Priscilla
----------------------------------
Priscilla Walmsley
Author, Definitive XML Schema
Definitive XQuery
http://www.datypic.com
----------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Apr 27 '06 #4
Hi Priscilla,

Perhaps you could suggest a good xml style guide or a tool better than
those that I am using? Both XmlSpy and a java validator I wrote myself
(sax parser) fail to choke on the problem use case that I have on hand.

Thanks again...
Jason

May 1 '06 #5

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

Similar topics

0
by: peterpeter | last post by:
Hi. There is a XML schema problem that I have with key/keyref: I have two complex (A and B) types which both inherit from a common base typ (Base). A refers B using a xs:IDREF element named...
0
by: Markus Seibold | last post by:
Hello NG, sorry for pasting that much code but I just can't figure out how get the <key><keyref> to work in XML Schema. I am using XMLSpy 4.3 for editing my XML. I want to represent a...
5
by: Russell O'Connor | last post by:
The following XML and Schema doesn't validate in Visual Studio .NET 2003. Is there some mistake I'm making, or is VS.NET in error. The error is r:\test2.xml(3): The key sequence 'foo' in Keyref...
0
by: mark.van.der.voort | last post by:
Hi, I have defined a simple key/keyref validation for describing a tree. <xs:key name="key_member"> <xs:selector xpath=".//member"/> <xs:field xpath="@id"/> </xs:key> <xs:keyref...
0
by: jacksuyu | last post by:
I have two xsd files, in one xsd file, I defined a "key", I'd like to use "keyref" to refer to that "key" from another xsd file. But I always get attribute is empty error. my.xsd is my first xsd...
1
by: Dmitry Martynov | last post by:
Hi I have a question whether XmlValidatingReader doesn't check keyref constrain (the same with key constraint) or I do smth wrong. I have the following schema <?xml version="1.0"...
0
by: Kent Boogaart | last post by:
Hi, Suppose an XSD as follows: <xsd:complexType name="myType"> <xsd:complexContent> <xsd:extension base="myBaseType"> <xsd:sequence> <xsd:element name="thing" minOccurs="0"...
2
by: svestin | last post by:
Hi All! I run into a problem defining a XSD schema with KEYREF references. Is it possible to use KEYREF with nillable fields? Just like a database where a FK could be null. In the example...
0
by: peterpeter | last post by:
Hi. There is a XML schema problem that I have with key/keyref: I have a complex type "AExtended" which inherits from a base type "ABase". Both are allowed to be instantiated under the "Root"...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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.