identity constraint volation not caught when xpath contains default namespace
-----------------------------------------------------------------------------
Key: XERCESC-1516
URL: http://issues.apache.org/jira/browse/XERCESC-1516
Project: Xerces-C++
Type: Bug
Components: Validating Parser (Schema) (Xerces 1.5 or up only)
Versions: 2.6.0
Environment: Windows XP
Reporter: Andrew Fang
The following schema contains an identity constraint on the uniqueness of ISBN
number. However, no error is reported when duplicated entries for ISBN exist.
The problem seem to be that XPath parser does not parse default namespace
correctly. If a prefix is added (xmlns:x="....") and use the prefix in xpath
expression (e.g. <xsd:selector xpath="x:Book"/> ...), the violation is found.
The following is a possible fix for the problem:
in XercesXpath.cpp ln 510 and 585, change
if (scopeContext && !aToken == -1) {
prefix = stringPool->getValueForId(aToken);
uri = scopeContext->getNamespaceForPrefix(prefix);
}
to
if (scopeContext) {
if(aToken == -1) { // no prefix, must be default namespace
prefix = XMLUni::fgZeroLenString;
} else {
prefix = stringPool->getValueForId(aToken);
}
uri = scopeContext->getNamespaceForPrefix(prefix);
}
------- Schema ---------------
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.publishing.org"
xmlns="http://www.publishing.org"
elementFormDefault="qualified">
<xsd:element name="BookCatalogue">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Book" minOccurs="1"
maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element
name="Title" type="xsd:string" minOccurs="1" maxOccurs="1"/>
<xsd:element
name="Author" type="xsd:string" minOccurs="1" maxOccurs="1"/>
<xsd:element
name="ISBN" type="xsd:string" minOccurs="1" maxOccurs="1"/>
<xsd:element
name="Publisher" type="xsd:string" minOccurs="1" maxOccurs="1"/>
<xsd:element
name="Date" type="xsd:string" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:unique name="ISBNnumber">
<xsd:selector xpath="Book"/>
<xsd:field xpath="ISBN"/>
</xsd:unique>
</xsd:element>
</xsd:schema>
--------- xml instance -----------
<?xml version="1.0" encoding="UTF-8"?>
<BookCatalogue
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.publishing.org"
xsi:schemaLocation="http://www.publishing.org idc001.nogen.xsd">
<Book>
<Title>My Life and Times</Title>
<Author>Paul McCartney</Author>
<ISBN>43892</ISBN>
<Publisher>McMillin Publishing</Publisher>
<Date>1998</Date>
</Book>
<Book>
<Title>My Life and Times</Title>
<Author>Paul McCartney</Author>
<ISBN>43892</ISBN>
<Publisher>McMillin Publishing</Publisher>
<Date>1998</Date>
</Book>
</BookCatalogue>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]