Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validating XML using XSD with regex pattern

Tags:

java

regex

xsd

sax

I am parsing a XML file against a XSD containing some regex patterns used for checking input data, but only this regex generates an error, even if it passes into the Eclipse XSD plugin:

   InvalidRegex: Pattern value 
   '(((com|org)\.)+(\b[a-z]+[.]{1}\b)+)?[A-Z]{1}[A-Za-z]+' 
   is not a valid regular expression. The reported error was: 
   'This expression is not supported in the current option setting.'.

So even if the problem is caused by the \b boundary which I can safely remove, with SAX validator where can I find the fatal "current option setting"?

like image 758
Steel Plume Avatar asked Apr 10 '10 15:04

Steel Plume


People also ask

How do you validate a RegEx pattern?

RegEx pattern validation can be added to text input type questions. To add validation, click on the Validation icon on the text input type question.

Does XML support RegEx?

XML schema always implicitly anchors the entire regular expression. The regex must match the whole element for the element to be considered valid. If you have the pattern regexp, the XML schema validator will apply it in the same way as say Perl, Java or . NET would do with the pattern ^regexp$.

How do I reference an XSD file in XML?

Reference the XSD schema in the XML document using XML schema instance attributes such as either xsi:schemaLocation or xsi:noNamespaceSchemaLocation. Add the XSD schema file to a schema cache and then connect that cache to the DOM document or SAX reader, prior to loading or parsing the XML document.


1 Answers

\b is not supported by the XML Schema regex flavor as specified by the W3C. The error message implies that you can use it anyway by changing a setting, but then you would be using a non-standard feature, which would defeat the purpose of using XML.

I'm not sure that's what the error message really means, but it would have been more helpful if it had just the regex was invalid. Do yourself a favor and forget about using \b in your XSD's. And check out the rest of the regular-expressions.info site if you haven't already--it's a great resource.

like image 170
Alan Moore Avatar answered Oct 20 '22 09:10

Alan Moore