Is there any difference between XSD: Pattern and C # Regex?

I cannot go into much of my project for a number of constraining reasons.

Essentially, I'm trying to pre-test an object before serializing it, and then check it for a schema. The schema has confirmation for the name, which I know is not ideal, and you better not check the name, but I cannot reproduce a valid regular expression for what the schema is trying to do.

<xsd:simpleType name="CharsetD"> <xsd:restriction base="xsd:string"> <xsd:pattern value="[A-Za-z \-&apos;]*"/> </xsd:restriction> </xsd:simpleType> <xsd:element minOccurs="0" maxOccurs="2" name="Fore"> <xsd:simpleType> <xsd:restriction base="CharsetD"> <xsd:minLength value="1"/> <xsd:maxLength value="35"/> <xsd:pattern value="[A-Za-z].*"/> </xsd:restriction> <xsd:simpleType> </xsd:element> 

In this case, I just thought I could try and just use xsd:pattern for charset .

I tried to use the [A-Za-z \-&apos;]* , which returned the name, such as Luke2 , as valid, but the check scheme said that it is not because it contains a number.

My question is, how can I repeat the above in one c# regex? Also, are there any differences between the way the schema template works than if I used it in .NET , what can I note in the future?

+6
source share
1 answer

I found the problem, albeit masked, because I didn’t work very much with XML Schema

Difference

The CharsetD type does not just use a template, since it is not good enough for checking names with numbers, so when I tried to use only a template, it allowed numbers. However, there is a type string that limits the numbers, and therefore why the circuit returns an error in which the regular expression does not exist.

 <xsd:restriction base="xsd:string"> 

Decision

I created another one regular expression that would use the string constraint that applies in my schema.

 ^[\p{L} \.\-]+$ 
+2
source

All Articles