问题描述
这是我的xsd:<?xmlversion="1.0"encoding="utf-8"?><xsd:schemaattributeFormDefault="unqualified"elementFormDefault="qualified"version="1.0"xmlns:xsd="http://www.w3.org/2001/XMLSchema"><xsd:elementname="MailStsDataSet"><xsd:complexType><xsd:sequence><xsd:elementmaxOccurs="unbounded"name="Mail_Cus_Sts"><xsd:complexType><xsd:sequence><xsd:elementname="ACT_TIME"type="xsd:dateTime"/><xsd:elementname="ACT_STATION"type="xsd:string"/><xsd:elementname="ACT"type="xsd:string"/></xsd:sequence></xsd:complexType></xsd:element></xsd:sequence></xsd:complexType></xsd:element></xsd:schema>这是我的xml:<?xmlversion="1.0"encoding="utf-8"?><MailStsDataSet><Mail_Cus_Sts><ACT_TIME>2014-07-2012:36:00</ACT_TIME><ACT_STATION>扬州速物邗江中路揽投部</ACT_STATION><ACT>收寄</ACT></Mail_Cus_Sts><Mail_Cus_Sts><ACT_TIME>2014-07-2017:42:55</ACT_TIME><ACT_STATION>扬州速物邗江中路揽投部</ACT_STATION><ACT>离开处理中心,发往扬州站点</ACT></Mail_Cus_Sts><Mail_Cus_Sts><ACT_TIME>2014-07-2106:45:35</ACT_TIME><ACT_STATION>扬州站点</ACT_STATION><ACT>离开处理中心,发往扬州速物广陵揽投部</ACT></Mail_Cus_Sts><Mail_Cus_Sts><ACT_TIME>2014-07-2108:24:00</ACT_TIME><ACT_STATION>扬州速物广陵揽投部</ACT_STATION><ACT>安排投递</ACT></Mail_Cus_Sts><Mail_Cus_Sts><ACT_TIME>2014-07-2108:25:54</ACT_TIME><ACT_STATION>扬州速物广陵揽投部</ACT_STATION><ACT>到达处理中心,来自扬州站点</ACT></Mail_Cus_Sts><Mail_Cus_Sts><ACT_TIME>2014-07-2110:44:00</ACT_TIME><ACT_STATION>扬州速物广陵揽投部</ACT_STATION><ACT>投递并签收</ACT></Mail_Cus_Sts></MailStsDataSet>这是我的验证代码:publicstaticvoidmain(String[]args){StringschemaLanguage=XMLConstants.W3C_XML_SCHEMA_NS_URI;SchemaFactoryschemaFactory=SchemaFactory.newInstance(schemaLanguage);Schemaschema=null;try{schema=schemaFactory.newSchema(newFile("D:\workspace\bh-connector\bh-connector-es\xsd\ems.xsd"));}catch(SAXExceptione){e.printStackTrace();}//unmarshaller.setSchema(schema);Validatorvalidator=schema.newValidator();InputSourceinputSource=null;try{inputSource=newInputSource(newFileInputStream(newFile("D:\workspace\bh-connector\bh-connector-es\xsd\ems.xml")));}catch(FileNotFoundExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}Sourcesource=newSAXSource(inputSource);try{validator.validate(source);}catch(SAXExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}System.out.println("success");}这是的错误代码:org.xml.sax.SAXParseException:cvc-datatype-valid.1.2.1:'2014-07-2012:36:00'isnotavalidvaluefor'date'.atcom.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)atcom.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)atcom.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)atcom.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)atcom.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:417)atcom.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3181)atcom.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLocallyValidType(XMLSchemaValidator.java:3096)atcom.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processElementContent(XMLSchemaValidator.java:3006)atcom.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleEndElement(XMLSchemaValidator.java:2149)atcom.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.endElement(XMLSchemaValidator.java:817)atcom.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.endElement(ValidatorHandlerImpl.java:563)atorg.apache.xerces.parsers.AbstractSAXParser.endElement(UnknownSource)atorg.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(UnknownSource)atorg.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(UnknownSource)atorg.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(UnknownSource)atorg.apache.xerces.parsers.XML11Configuration.parse(UnknownSource)atorg.apache.xerces.parsers.XML11Configuration.parse(UnknownSource)atorg.apache.xerces.parsers.XMLParser.parse(UnknownSource)atorg.apache.xerces.parsers.AbstractSAXParser.parse(UnknownSource)atcom.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.validate(ValidatorHandlerImpl.java:697)atcom.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:97)atjavax.xml.validation.Validator.validate(Validator.java:127)atcn.baozun.bh.connector.sf.manager.TestLogisticsRouteQuery.main(TestLogisticsRouteQuery.java:167)success求大神赐教
解决方案
解决方案二:
org.xml.sax.SAXParseException:cvc-datatype-valid.1.2.1:'2014-07-2012:36:00'isnotavalidvaluefor'dateTime'.atcom.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)atcom.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)atcom.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)atcom.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)atcom.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:417)atcom.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3181)atcom.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLocallyValidType(XMLSchemaValidator.java:3096)atcom.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processElementContent(XMLSchemaValidator.java:3006)atcom.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleEndElement(XMLSchemaValidator.java:2149)atcom.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.endElement(XMLSchemaValidator.java:817)atcom.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.endElement(ValidatorHandlerImpl.java:563)atorg.apache.xerces.parsers.AbstractSAXParser.endElement(UnknownSource)atorg.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(UnknownSource)atorg.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(UnknownSource)atorg.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(UnknownSource)atorg.apache.xerces.parsers.XML11Configuration.parse(UnknownSource)atorg.apache.xerces.parsers.XML11Configuration.parse(UnknownSource)atorg.apache.xerces.parsers.XMLParser.parse(UnknownSource)atorg.apache.xerces.parsers.AbstractSAXParser.parse(UnknownSource)atcom.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.validate(ValidatorHandlerImpl.java:697)atcom.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:97)atjavax.xml.validation.Validator.validate(Validator.java:127)atcn.baozun.bh.connector.sf.manager.TestLogisticsRouteQuery.main(TestLogisticsRouteQuery.java:167)success