RE: regular expression matching in <assert>

Jim Barnett <[email protected]>
Newsgroups gmane.text.xml.xerces-j.user
Message-ID <57A15FAF9E58F841B2B1651FFE16D281038AC0@GENSJZMBX02.msg.int.genesyslab.com>
Mukul,
  Thanks for your response.  I've attached a sample schema and test file (the schema is edited down from a much larger document, so it's structure may not make much sense.)   The problem is in the <assert> in line 74 of the schema.  (The simpler <assert> in line 73 works properly.)  

I suspect that you may be right about there being a namespace problem, because the <assert> in line 74 fails even if I wrap not() around it.  So both

<xsd:assert test="if (matches(@target, '.*')) then true() else false()"  xpathDefaultNamespace="##targetNamespace"/>
And
<xsd:assert test="if not((matches(@target, '.*'))) then true() else false()"  xpathDefaultNamespace="##targetNamespace"/>

both fail, which makes it look like the processor is not finding the matches() function.  

The 'xpathDefaultNamespace="##targetNamespace"' attribute is something I stumbled across when trying to get some other assertions to work, but I admit that I don't really understand what effects it may be having.  

Thank you for your help.  

- Jim

-----Original Message-----
From: Mukul Gandhi [mailto:[email protected]] 
Sent: Wednesday, April 17, 2013 10:55 AM
To: [email protected]
Subject: Re: regular expression matching in <assert>

Hi Jim,
    Our XSD 1.1 <assert> implementation can use XPath 2.0 matches() and tokenize() functions fine. Our <assert> XPath 2.0 processor passes all W3C XPath 2.0 tests.

I've checked your example with current Xerces SVN, and I don't find any bug wrt your example. I can see, that you use the xpathDefaultNamespace attribute on <assert> which may be causing issues.

If you can post a complete XSD schema document along with an XML instance document, we could debug better.

On Wed, Apr 17, 2013 at 12:12 AM, Jim Barnett <[email protected]> wrote:
> Are matches() and tokenize() supported inside <assert> when doing 
> schema validation?  I am applying an assertion to an element with a 'target'
> attribute whose value is "s1 s2", yet the following assertion is failing:
>
>
>
> <xsd:assert test="if (matches(@target, '.*')) then true()  else false()"
> xpathDefaultNamespace="##targetNamespace"/>
>
>
>
> Any guidance would be appreciated.
>
>
>
> Thanks,
>
> Jim



--
Regards,
Mukul Gandhi

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
test_schema.xsd (text/xml, 2.8 KB)
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.w3.org/2005/07/scxml"
    xmlns="http://www.w3.org/2005/07/scxml"
    elementFormDefault="qualified">
	

	<!-- scxml -->
	<xsd:attributeGroup name="scxml.scxml.attlist">
		<xsd:attribute name="initial" type="xsd:IDREFS"/>
	</xsd:attributeGroup>
	<xsd:group name="scxml.scxml.mix">
		<xsd:choice>
			<xsd:element ref="state" minOccurs="0" maxOccurs="unbounded"/>
		</xsd:choice>
	</xsd:group>
	<xsd:group name="scxml.scxml.content">
		<xsd:sequence>
			<xsd:group ref="scxml.scxml.mix" minOccurs="0" maxOccurs="unbounded"/>
		</xsd:sequence>
	</xsd:group>
	<xsd:complexType name="scxml.scxml.type">
		<xsd:group ref="scxml.scxml.content"/>
		<xsd:attributeGroup ref="scxml.scxml.attlist"/>
	</xsd:complexType>
	<xsd:element name="scxml" type="scxml.scxml.type"/>

	<!-- state -->
	<xsd:attributeGroup name="scxml.state.attlist">
		<xsd:attribute name="id" type="xsd:ID"/>
		<xsd:attribute name="initial" type="xsd:IDREFS"/>
	</xsd:attributeGroup>
	<xsd:group name="scxml.state.mix">
		<xsd:choice>
			<xsd:element ref="transition" minOccurs="0" maxOccurs="unbounded"/>
			<xsd:element ref="state" minOccurs="0" maxOccurs="unbounded"/>
		</xsd:choice>
	</xsd:group>
	<xsd:group name="scxml.state.content">
		<xsd:sequence>
			<xsd:group ref="scxml.state.mix" minOccurs="0" maxOccurs="unbounded"/>
		</xsd:sequence>
	</xsd:group>
	<xsd:complexType name="scxml.state.type">
		<xsd:sequence>
			<xsd:group ref="scxml.state.content"/>
		</xsd:sequence>	
		<xsd:attributeGroup ref="scxml.state.attlist"/>		
	</xsd:complexType>
	<xsd:element name="state" type="scxml.state.type"/>


	<!-- transition -->
	<xsd:attributeGroup name="scxml.transition.attlist">
		<xsd:attribute name="target" type="xsd:IDREFS"/>
	</xsd:attributeGroup>
<xsd:group name="scxml.transition.mix">
		<xsd:choice>
			<xsd:element ref="transition" minOccurs="0" maxOccurs="unbounded"/>
			<xsd:element ref="state" minOccurs="0" maxOccurs="unbounded"/>
		</xsd:choice>
	</xsd:group>
	<xsd:group name="scxml.transition.content">
		<xsd:sequence>
			<xsd:group ref="scxml.transition.mix" minOccurs="0" maxOccurs="unbounded"/>
		</xsd:sequence>
	</xsd:group>
	<xsd:complexType name="scxml.transition.type">
			<xsd:sequence>
			<xsd:group ref="scxml.transition.content"/>
		</xsd:sequence>	
		<xsd:attributeGroup ref="scxml.transition.attlist"/>
		<xsd:assert test="(@event or @cond or @target)" xpathDefaultNamespace="##targetNamespace"/>
		<xsd:assert test="if (matches(@target, '.*')) then true()
			 else false()"  xpathDefaultNamespace="##targetNamespace"/>
	</xsd:complexType>
	<xsd:element name="transition" type="scxml.transition.type"/>


</xsd:schema>
sample.scxml (application/octet-stream, 324 B) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.