Re: xhtml.xsd error?

Hi Luís,

I tried this pattern on Perl and the expression does match 100.5%.  See [1]
for more.

I think the wording of the paragraph you quote is sub-optimal!  Where is
says "When one pattern completely matches, ..." I think it means "If a match
for the complete pattern is found, ..." as opposed to just the one
sub-expression.

The pattern shown is something like C?(A|BD?E).  Even though A does match a
portion of the target 100.5%, C?A does not match the entire pattern, so the
regular expression engine back tracks and tries C?BD?E.

Regards,

Pete.

[1]
Perl code:
#!/usr/bin/perl -w

@vals = qw( 100 100.0 100% 100.0% +100 +100.0 +100% +100.0%
            -100 -100.0 -100% -100.0% 100.5% );

foreach $v (@vals) {
    if( $v =~ /^[-+]?(\d+|\d+(\.\d+)?%)$/ ) {    # Added in ^ and $
        print "$v - It matches\n";
    }
    else {
        print "$v - No match\n";
    }
}

Result:
100 - It matches
100.0 - No match
100% - It matches
100.0% - It matches
+100 - It matches
+100.0 - No match
+100% - It matches
+100.0% - It matches
-100 - It matches
-100.0 - No match
-100% - It matches
-100.0% - It matches
100.5% - It matches
--
=============================================
Pete Cordell
Tech-Know-Ware Ltd
                         for XML to C++ data binding visit
                         http://www.tech-know-ware.com/lmx
                         (or http://www.xml2cpp.com)
=============================================

----- Original Message ----- 
From: "Luís Fernando Heckler" <lfheckler@ig.com.br>
To: "Michael Kay" <mike@saxonica.com>
Cc: <xmlschema-dev@w3.org>
Sent: Tuesday, August 08, 2006 2:10 PM
Subject: Re: xhtml.xsd error?



Thanks Michael !

All right, this make sense, but the original Regular Expression
"[-+]?(\d+|\d+(\.\d+)?%)" doesn't match values like "100.5%".

At http://docs.python.org/lib/re-syntax.html we can read:
"|A|B|, where A and B can be arbitrary REs, creates a regular expression
that will match either A or B. An arbitrary number of REs can be
separated by the "|" in this way. This can be used inside groups (see
below) as well. As the target string is scanned, REs separated by "|"
are tried from left to right. When one pattern completely matches, that
branch is accepted. This means that once |A| matches, |B| will not be
tested further, even if it would produce a longer overall match. In
other words, the "|" operator is never greedy."

So, the original expression match the substring "100" first and stop.

An alternative could be: "[-+]?(\d+(\.\d+)?%|\d+)"
This recognize:

100
100%
100.0%
+100
+100%
+100.0%
-100
-100%
-100.0%

But also recognize strings like "1000000000.3332%" ... this is correct,
but weird.


Luís Fernando Heckler



Michael Kay escreveu:
> This picture allows a decimal point only if there is a "%", which seems
> reasonable, because you can't have a fractional number of pixels.
>
> Michael Kay
> http://www.saxonica.com/
>
>
>
>> -----Original Message-----
>> From: xmlschema-dev-request@w3.org [mailto:xmlschema-dev-request@w3.org] 
>> On Behalf Of Luis Fernando Heckler
>> Sent: 02 August 2006 20:01
>> To: xmlschema-dev@w3.org
>> Subject: xhtml.xsd error?
>>
>>
>> Hi,
>>
>> I'm using the w3c xhtml.xsd to validate my xhtml document, but I found 
>> something wrong:
>>
>> In the simpleType definition named Length (line 203), used to validate de 
>> type of attributes width and heigth of table element for example, we have 
>> a pattern to validate the type, but this pattern doesn't match witch all 
>> the expected formats (AFAIK).
>>
>> http://www.w3.org/TR/xhtml-modularization/abstraction.html#dt_
>> Length  say's:
>> "Length - The value may be either in pixels or a percentage of the 
>> available horizontal or vertical space. Thus, the value "50%" means half 
>> of the available space."
>>
>> The documentation comment in the xsd say's:
>> "nn for pixels or nn% for percentage length"
>>
>> So, I thing that expected values are:
>> 100
>> 100.0
>> 100%
>> 100.0%
>> +100
>> +100.0
>> +100%
>> +100.0%
>> -100
>> -100.0
>> -100%
>> -100.0%
>>
>> But the original pattern "[-+]?(\d+|\d+(\.\d+)?%)" don't match all this 
>> length formats.
>>
>> I change to "[-+]?\d+(\.\d+)?%?"
>>
>> This is a error in original w3c xhtml.xsd or I'm wrong about the expected 
>> length formats?
>>
>> Best wishes
>> Luis Fernando Heckler
>>
>>
>>
>>
>>
>>
>
>
>
>
>

Received on Wednesday, 9 August 2006 09:12:42 UTC