Project

Profile

Help

XML Schema validation and regular expression

Added by Anonymous almost 15 years ago

Legacy ID: #7501791 Legacy Poster: Claudio Tasso (tassoc)

Hi, I'm using an evaluation version of Saxon 9-1-0-7j. I'm trying loading an XML Schema containing a pattern restriction like the following: <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="^(?=\d)(?:(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?:\x20|$))|(?:2[0-8]|1\d|0?[1-9]))([-./])(?:1[012]|0?[1-9])\1(?:1[6-9]|[2-9]\d)?\d\d(?:(?=\x20\d)\x20|$))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$" /> </xs:restriction> It's a regular expression found on the web and it uses some Perl 5 extensions. Its syntax is correct, I verified it using java.util.regex classes. I used the following code in order to execute validation: SchemaFactory schemaFactory = (SchemaFactory)Class.forName("com.saxonica.jaxp.SchemaFactoryImpl").newInstance(); Schema schemaGrammar = schemaFactory.newSchema(new File("prova.xsd")); Validator schemaValidator = schemaGrammar.newValidator(); but an exception is raised: net.sf.saxon.type.SchemaException: One error was found while processing the schema at com.saxonica.jaxp.SchemaFactoryImpl.newSchema(SchemaFactoryImpl.java:195) at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:489) at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:505) at com.crif.ParserTest.saxon(ParserTest.java:33) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99) at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81) at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34) at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75) at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45) at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66) at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35) at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42) at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34) at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) and the following message is logged: Error at xs:pattern on line 29 column 382 of prova.xsd: Error at character 2 in regular expression "^(?=\d)(?:(?:31(?!.(?:0?[2469]...": expected ()) Does any configuration option exist which allows the correct evaluation of that regular expression? Thanks in advance


Replies (1)

RE: XML Schema validation and regular expression - Added by Anonymous almost 15 years ago

Legacy ID: #7501826 Legacy Poster: Michael Kay (mhkay)

The XML Schema spec supports a much smaller regular expression language than Perl or Java, and Saxon sticks rigorously to the spec. I'm afraid I can't volunteer to translate your regex into this dialect.

    (1-1/1)

    Please register to reply