users@jaxb.java.net

Re: Error while trying to parse a xml schema : InvalidRegex

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Wed, 10 Mar 2010 09:24:35 +0100

There is no way around fixing the broken regular expression in the XML schema.
'[EAN][0-9]{1,3}([NOZWLR])?[-]([abcdefghjkmnpqrstuvwxyz][-])?[0-9]{1,3}[-
]\d{3}-DR[1-9]'

Each of the '[-]' is bad and should be written as [\-] or simply '-'

-W



On Tue, Mar 9, 2010 at 10:46 AM, Jithin Jayaram
<jithinjayaram_at_arssoftware.com> wrote:
>
>
>
>
>
> From: Jithin Jayaram [mailto:jithinjayaram_at_arssoftware.com]
> Sent: Tuesday, March 09, 2010 3:04 PM
> To: 'users_at_jaxb.dev.java.net'
> Subject: Error while trying to parse a xml schema : InvalidRegex
>
>
>
> Hi,
>
>
>
> Jaxb version used : 2.1.9
>
> Java version : 1.5
>
>
>
>  I am getting the following error while trying to parse an xml schema document in my program.
>
>
>
> org.xml.sax.SAXParseException: InvalidRegex: Pattern value '[EAN][0-9]{1,3}([NOZWLR])?[-]([abcdefghjkmnpqrstuvwxyz][-])?[0-9]{1,3}[- ]\d{3}-DR[1-9]' is not a valid regular expression. The reported error was: ''-' is an invalid character range. Write '\-'.'.
>
>       at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
>
>       at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
>
>       at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)...73..xmlSchemaPath : F:\workspace\XMLParser\src\conf\cggosall.xsd
>
>       at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaError(Unknown Source)
>
>       at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDAbstractTraverser.reportSchemaError(Unknown Source)
>
>       at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDSimpleTypeTraverser.traverseSimpleTypeDecl(Unknown Source)
>
>       at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDSimpleTypeTraverser.traverseGlobal(Unknown Source)
>
>       at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getGlobalDecl(Unknown Source)
>
>       at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDAttributeTraverser.traverseNamedAttr(Unknown Source)
>
>       at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDAttributeTraverser.traverseLocal(Unknown Source)
>
>       at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDAbstractTraverser.traverseAttrsAndAttrGrps(Unknown Source)
>
>       at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDComplexTypeTraverser.processComplexContent(Unknown Source)
>
>       at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDComplexTypeTraverser.traverseComplexTypeDecl(Unknown Source)
>
>       at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDComplexTypeTraverser.traverseGlobal(Unknown Source)
>
>       at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.traverseSchemas(Unknown Source)
>
>       at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
>
>       at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
>
>       at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
>
>       at com.sun.org.apache.xerces.internal.jaxp.validation.xs.SchemaFactoryImpl.newSchema(Unknown Source)
>
>       at javax.xml.validation.SchemaFactory.newSchema(Unknown Source)
>
>       at javax.xml.validation.SchemaFactory.newSchema(Unknown Source)
>
>       at com.arsse.ossim.util.CggosallXMLParser.parser(CggosallXMLParser.java:88)
>
>       at com.arsse.ossim.util.CggosallXMLParser.<init>(CggosallXMLParser.java:64)
>
>       at com.arsse.ossim.util.CggosAllXMLParserTester.main(CggosAllXMLParserTester.java:25)
>
>
>
>
>
> The code snippet I used to parse the document is given below.
>
> JAXBContext  jcontext = JAXBContext.newInstance(contextPackage);
>
>             SchemaFactory sf = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI );
>
>             Schema mySchema = sf.newSchema(new File(xmlSchemaPath));
>
>             Unmarshaller unmarshaller = jcontext.createUnmarshaller();
>
>             unmarshaller.setSchema(mySchema);
>
>
>
> The error occurs during the execution of third line.
>
>
>
> The same error also occurred when I was trying to generate the classes from the xml schema using the xjc.But by giving the parameters –nv I was able to generate the classes. I used the following command to generate the classes.
>
> F:\ xjc –nv cggossall.xsd –p com.generated
>
>
>
> Thanks & Regards
>
> - Jithin Jayaram, Software Engineer