I have a 2 part question:
-
How can I get the
regexexpression of anXSDfacet and then use it to determine if a string matches the restriction? In my mind, this is “How do I convert XML Schema regex to .NETRegex“, but I’m open for suggestions if you have another way for me to do it other than converting the expression. -
If the test (#1) fails, how can I use the
XSDpatternregexto automatically create a string which does satisfy the constraint?
XmlSchemaDatatype.ParseValue is your answer. Assuming the associated simple type has more facets and you only want to validate against the pattern one(s), then you have to simply find the enumeration facet in the XmlSchemaSimpleTypeRestriction.Facets, use a copy of that to create a new XmlSchemaSimpleType, with a new XmlSchemaSimpleTypeRestriction Content and new pattern facet(s) using the values you scooped above. Then using this newly created simple type, invoke XmlSchemaDatatype.ParseValue.
I would advise against your suggestion in the comment, since the regex “dialects” are different.
I am not aware of such a thing, available for free or otherwise. I am sure it can be done but I never found something that would actually work, when I needed it myself. If you do find one, please share.