Avatar billede fredand Forsker
21. april 2011 - 09:40 Der er 2 kommentarer og
1 løsning

How to create a pattern for a scale in a xsd?

Hello!

I need create a pattern in for an string element in an xsd.
It should describe a scale for an image.
I think it needs to support values like
1:1
1:123
123:1
etc.

My idea is to do it like this but I do not know the syntax for the pattern that should restrict this.

I'm really bad at reg exp. so I hope for some help here.

<xs:simpleType name="ScaleType">
<xs:restriction base="xs:string">
<xs:pattern value="\S.{4-DIGITS}:\S.{4-DIGITS}">
</xs:restriction>
</xs:simpleType>

The part \S.{4-DIGITS}:\S.{4-DIGITS} is where I do think I do not get it right. It should support.
The ideal would be if it could support either:
\S.{1-DIGITS}:\S.{4-DIGITS} like 1:1234
or
\S.{4-DIGITS}:\S.{1-DIGITS} like 1234:1

Any ideas is most welcome.

Best regards
Fredrik
Avatar billede arne_v Ekspert
09. maj 2011 - 00:12 #1
Most obvious to me:

"(\d{1}:\d{4})|(\d{4}:\d{1})"
Avatar billede fredand Forsker
09. maj 2011 - 08:21 #2
Hello Arne!

Wow! I did not know you could combine patterns with "|" in a regexp. I do need to study the regexp more!
Really smooth solution!

I will test it during this day, but since I bet it works fine, please give a svar!

Best regards!
Fredrik
Avatar billede arne_v Ekspert
09. maj 2011 - 19:05 #3
svar
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester