Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Allowing Either a patter or a null value in an Element?

From: "Thomas Malia" <tommalia@--------.---.--->
To: NULL
Date: 6/1/2006 12:07:00 PM

I don't know which validator XMLSpy">XMLSpy is using, but it doesn't appear to be 
behaving the same way you're describing.

BUT!  Doesn't matter now!

The multiple pattern element idea appears to work just great!!!!  Thanks!
I didn't realize that you were allowed to put more than one pattern element 
in.

Thank you very much!

"Priscilla Walmsley" <nospam@d...> wrote in message 
news:ek6ObfYhGHA.1276@T......
> Hi,
>
> The validators I'm using (Xerces and Saxon) treat a zero-length regular 
> expression (which is what you have after the "|") as only matching a 
> zero-length string, so it shouldn't negate the validation of requiring 
> digits.
>
> You could also try
> <xs:simpleType name="DfltAddrPhone_Type">
>   <xs:restriction base="xs:string">
>       <xs:pattern value="\d{10,15}"/>
>       <xs:pattern value=""/>
>   </xs:restriction>
> </xs:simpleType>
>
> which also should match either pattern.  Maybe your processor handles this 
> one correctly.
>
> If that doesn't work, you can use a union type, as in:
>
> <xs:simpleType name="SizeType">
>   <xs:union>
>      <xs:simpleType>
>         <xs:restriction base="xs:string">
>            <xs:pattern value="\d{10,15}"/>
>         </xs:restriction>
>      </xs:simpleType>
>      <xs:simpleType>
>         <xs:restriction base="xs:string">
>            <xs:enumeration value=""/>
>         </xs:restriction>
>      </xs:simpleType>
>   </xs:union>
> </xs:simpleType>
>
> Hope that helps,
> Priscilla
>
> -------------------------------------------------------------------------
> Priscilla Walmsley http://www.datypic.com
> Author, Definitive XML Schema / XML in Office 2003
>            XQuery (coming in 2006 from O'Reilly)
> -------------------------------------------------------------------------
> "Thomas Malia" <tommalia@w...> wrote in message 
> news:eG2KwMYhGHA.1792@T......
>> Thanks,
>>
>> I tried leaving everything after the | blank... the problem is this seems 
>> to negate the validation of reqiring digits.  With what you descibed 
>> here, I did not get a validation error if the field had a value of say 
>> "THOMAS"... it took that as a valid value.
>>
>> The rule I wanted was, either you give me 10 to 15 digits OR you leave 
>> the thing blank... nothing else is allowed.
>>
>> So far, the only solution I've come up with is to set the nillable 
>> attribute to true and make the pattern: ="\d{10,15}".  This doesn't 
>> result in exactly what I want because the XML document has to explicitly 
>> set the elements nil attribute for it to pass, but that's not the worst 
>> thing in the world.
>>
>>
>> "Priscilla Walmsley" <nospam@d...> wrote in message 
>> news:euenGdZgGHA.4976@T......
>>> Hi,
>>>
>>> The "^" character as an anchor is not supported by XML Schema. You can 
>>> just leave off everything after the | character, though, as in:
>>>
>>> <xs:simpleType name="DfltAddrPhone_Type">
>>>    <xs:restriction base="xs:string">
>>>        <xs:pattern value="\d{10,15}|"/>
>>>    </xs:restriction>
>>> </xs:simpleType>
>>>
>>> (I also slightly simplified the 10-15 digit part and took out the length 
>>> constraints because they were redundant.)
>>>
>>> Hope that helps,
>>> Priscilla
>>>
>>> -------------------------------------------------------------------------
>>> Priscilla Walmsley http://www.datypic.com
>>> Author, Definitive XML Schema / XML in Office 2003
>>>             XQuery (coming in 2006 from O'Reilly)
>>> -------------------------------------------------------------------------
>>>
>>> "Thomas Malia" <tommalia@w...> wrote in message 
>>> news:%237nimVpfGHA.5100@T......
>>>>I want to create an XML Schema Type definition that will either allow 
>>>>the XML document to level the element blank or if they supply any data 
>>>>it must match a pattern.
>>>>
>>>> The one example I'm currently working on is a Phone number field.
>>>>
>>>> I'd like to have something like:
>>>> <xs:simpleType name="DfltAddrPhone_Type">
>>>>
>>>>    <xs:restriction base="xs:string">
>>>>
>>>>        <xs:maxLength value="15"/>
>>>>
>>>>        <xs:minLength value="0"/>
>>>>
>>>>        <xs:pattern value="(\d{10})(\d)*|^*"/>
>>>>
>>>>    </xs:restriction>
>>>>
>>>> </xs:simpleType>
>>>>
>>>>
>>>>
>>>> When I use the above definition in XMLSpy">XMLSpy it works fine.  The regular 
>>>> expression in the patter allows the creation of an element that has at 
>>>> least 10 digit (\d{10}) with up to 5 more digits allowed for the 
>>>> extention (\d)* OR (|) NOT anything at all (^*).
>>>>
>>>> However, when use this schema to validate a XML file with MSXML it 
>>>> flags an empty phone number as violating the retstriction.  Also, if I 
>>>> try to generate java classes from the schema using XMLBeans it says my 
>>>> regular expression is invalid.  They both seem to not like the (^*) 
>>>> aspect.
>>>>
>>>> Is there some other way I can achieve what I'm after besides putting it 
>>>> in the regular expression for the pattern?  Or is there a better way to 
>>>> build the regular expression? (I'm DEFINATELY no RegExp expert)
>>>>
>>>>
>>>>
>>>> Thanks in advance,
>>>>
>>>> Tom Malia
>>>>
>>>>
>>>
>>>
>>
>>
>
> 




transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent