You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Jim Barnett <Ji...@genesyslab.com> on 2013/04/16 20:42:07 UTC

regular expression matching in

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

Re: regular expression matching in

Posted by Dawid Chodura <da...@gmail.com>.
I have no easy way to test it, but I think your expression could be simplified, ie.

test="if (matches(string(@target), '.*')) then true() else false()"

seems to be the same as

test="matches(string(@target), '.*'))"

I've checked the following URL:

http://www.w3.org/TR/xquery-operators/#func-matches

and it seems that "matches" returns xs:boolean:

fn:matches($input as xs:string?, $pattern as xs:string) as xs:boolean
Summary: The function returns true if $input matches the regular expression supplied as $pattern as influenced by the value of $flags, if present; otherwise, it returns false.

Best regards,
Dawid


W dniu 17.04.2013 19:28, Jim Barnett pisze:
> Mukul,
>    Yes, that fixed it.  Thank you for your prompt reply.
>
> - Jim
>
> -----Original Message-----
> From: Mukul Gandhi [mailto:mukulg@apache.org]
> Sent: Wednesday, April 17, 2013 12:26 PM
> To: j-users@xerces.apache.org
> Subject: Re: regular expression matching in <assert>
>
> Hi Jim,
>      Thanks for sending across the schema and XML instance documents. I looked at the schema document you've shared.
>
> The following fix seems to work for your problem <assert>,
>
> <xsd:assert test="if (matches(string(@target), '.*')) then true() else false()"  xpathDefaultNamespace="##targetNamespace"/>
>
> i.e, we use a string() function around attribute node @target. The 'target' attribute within your schema has type annotation of xsd:IDREFS, therefore we seem to need this workaround.
>
> On Wed, Apr 17, 2013 at 9:06 PM, Jim Barnett <Ji...@genesyslab.com> wrote:
>> 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
>
>
>
>
> --
> Regards,
> Mukul Gandhi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


RE: regular expression matching in

Posted by Jim Barnett <Ji...@genesyslab.com>.
Mukul,
  Yes, that fixed it.  Thank you for your prompt reply.

- Jim

-----Original Message-----
From: Mukul Gandhi [mailto:mukulg@apache.org] 
Sent: Wednesday, April 17, 2013 12:26 PM
To: j-users@xerces.apache.org
Subject: Re: regular expression matching in <assert>

Hi Jim,
    Thanks for sending across the schema and XML instance documents. I looked at the schema document you've shared.

The following fix seems to work for your problem <assert>,

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

i.e, we use a string() function around attribute node @target. The 'target' attribute within your schema has type annotation of xsd:IDREFS, therefore we seem to need this workaround.

On Wed, Apr 17, 2013 at 9:06 PM, Jim Barnett <Ji...@genesyslab.com> wrote:
> 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




--
Regards,
Mukul Gandhi

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: regular expression matching in

Posted by Mukul Gandhi <mu...@apache.org>.
Hi Jim,
    Thanks for sending across the schema and XML instance documents. I
looked at the schema document you've shared.

The following fix seems to work for your problem <assert>,

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

i.e, we use a string() function around attribute node @target. The
'target' attribute within your schema has type annotation of
xsd:IDREFS, therefore we seem to need this workaround.

On Wed, Apr 17, 2013 at 9:06 PM, Jim Barnett <Ji...@genesyslab.com> wrote:
> 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




-- 
Regards,
Mukul Gandhi

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


RE: regular expression matching in

Posted by Jim Barnett <Ji...@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:mukulg@apache.org] 
Sent: Wednesday, April 17, 2013 10:55 AM
To: j-users@xerces.apache.org
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 <Ji...@genesyslab.com> 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: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org

Re: regular expression matching in

Posted by Mukul Gandhi <mu...@apache.org>.
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
<Ji...@genesyslab.com> 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: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org