Error validating xml with xsd schema on JSDK 1.4

Hi All,
Asked to me do it a Web Service client in Java and validate its xml answer with an xsd file using 1.4 plataform.
I googled and I saw many samples to 1.5 plataform, and few samples to 1.4, but anyway I tried to do what they asked to me.
I got connect with service, got the response and so I went to validate that xml with an xsd file.
But I got an error on that task. The error occurs in the following line
"Schema schema = factory.getSchema();"
Bellow my code
final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
          final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
          final String schemaSource = "C:\\GetAuthorizationServiceOutput.xsd";
          final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();          
          factory.setNamespaceAware(true);
          factory.setValidating(true);
          try {
          factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
          factory.setAttribute(JAXP_SCHEMA_SOURCE,new File(source));
          catch (IllegalArgumentException x) {
               System.out.println(x.getMessage());
DocumentBuilder builder = null;
          Document document = null;
          try {
               builder = factory.newDocumentBuilder();
               document = builder.parse(new InputSource(new StringReader(ret.toString())));
          } catch (ParserConfigurationException e) {
               e.printStackTrace();
          } catch (SAXException e) {
               e.printStackTrace();
          } catch (IOException e) {
               e.printStackTrace();
          **Schema schema = factory.getSchema();**
          Validator validator = schema.newValidator();
          try {
               validator.validate(new DOMSource(document));
          } catch (SAXException e) {
               e.printStackTrace();
          } catch (IOException e) {
               e.printStackTrace();
and here is the exception :
Caused by: java.lang.NoSuchMethodError: javax.xml.parsers.DocumentBuilderFactory.getSchema()Ljavax/xml/validation/Schema;
Method onLinkClicked of interface wicket.markup.html.link.ILinkListener targeted at component [MarkupContainer [Component id = btBack, page = br.com.weev.finan.mkb_er.extranet.view.relations.RelationsDetails, path = 30:form:btBack.RelationsDetails$4, isVisible = true, isVersioned = true]] threw an exception
wicket.WicketRuntimeException: Method onLinkClicked of interface wicket.markup.html.link.ILinkListener targeted at component [MarkupContainer [Component id = btBack, page = br.com.weev.finan.mkb_er.extranet.view.relations.RelationsDetails, path = 30:form:btBack.RelationsDetails$4, isVisible = true, isVersioned = true]] threw an exception
     at wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:198)
     at wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:74)
     at wicket.request.compound.DefaultEventProcessorStrategy.processEvents(DefaultEventProcessorStrategy.java:65)
     at wicket.request.compound.AbstractCompoundRequestCycleProcessor.processEvents(AbstractCompoundRequestCycleProcessor.java:57)
     at wicket.RequestCycle.doProcessEventsAndRespond(RequestCycle.java:896)
     at wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:929)
     at wicket.RequestCycle.step(RequestCycle.java:1010)
     at wicket.RequestCycle.steps(RequestCycle.java:1084)
     at wicket.RequestCycle.request(RequestCycle.java:454)
     at wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:219)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
     at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
     at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
     at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
     at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
     at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
     at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
     at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
     at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
     at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
     at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
     at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.reflect.InvocationTargetException
     at sun.reflect.GeneratedMethodAccessor342.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:324)
     at wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:187)
     ... 39 more
Caused by: java.lang.NoSuchMethodError: javax.xml.parsers.DocumentBuilderFactory.getSchema()Ljavax/xml/validation/Schema;
     at br.com.weev.finan.mkb_er.business.manager.impl.RelationManagerImpl.getAuthorizationService(RelationManagerImpl.java:152)
     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:324)
     at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:296)
     at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:177)
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
     at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
     at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
     at $Proxy22.getAuthorizationService(Unknown Source)
     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:324)
     at wicket.proxy.LazyInitProxyFactory$JdkHandler.invoke(LazyInitProxyFactory.java:377)
     at wicket.proxy.$Proxy39.getAuthorizationService(Unknown Source)
     at br.com.weev.finan.mkb_er.extranet.view.relations.RelationsDetails$4.onClick(RelationsDetails.java:125)
     at wicket.markup.html.link.Link.onLinkClicked(Link.java:254)
     ... 43 more
It's my first time doing that, so I'm confuse to do it.
Thank you
Juliano.

This is how.
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
dbfac.setNamespaceAware(true);
SchemaFactory factory1 = SchemaFactory
                    .newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = factory1.newSchema(new File("person.xsd"));
dbfac.setSchema(schema);
DocumentBuilder dbparser1 = dbfac.newDocumentBuilder();
Document doc1 = dbparser1.parse(new File("person.xml"));
Validator validator1 = schema.newValidator();
DOMSource dm1 = new DOMSource(doc1);
DOMResult domresult1 = new DOMResult();
validator1.validate(dm1, domresult1);

Similar Messages

  • IllegalArgumentException - error validating xml with schema

    I'm trying to validate an XML document using the following:
    JAXP 1.2
    Xerces 1.4.4
    JDK 1.4.1
    The xml is valid and I can confirm it with XML Spy when I point it to the schema definition. But, I get an IllegalArgumentException when I try to do it in my class.
    Here's the code...
    public static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
    public static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
    public static final String CIS_SCHEMA = "D:\\dev\\xml\\cis.xsd";
    public static final String[] SCHEMAS = { W3C_XML_SCHEMA, CIS_SCHEMA };
    private static DocumentBuilderFactory dbf;
    private static DocumentBuilder db;
    try {
         dbf.setNamespaceAware(true);
         dbf.setValidating(true);
         dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, SCHEMAS);
    } (catch ...) {
    I get the following error:
    java.lang.IllegalArgumentException: http://java.sun.com/xml/jaxp/properties/schemaLanguage
    Any ideas?

    When I tried this with Xerces SAX, I got---
    org.xml.sax.SAXNotRecognizedException: http://java.sun.com/xml/jaxp/properties/schemaLanguage
    Maybe Xerces has not implemented the schemaLanguage property.
    I have been successfully using Xerces-dependent properties to do validation:
    XMLReader parser = saxParser.getXMLReader();
    parser.setFeature( "http://xml.org/sax/features/validation", true);
    parser.setFeature( "http://xml.org/sax/features/namespaces", true);
    parser.setFeature( "http://apache.org/xml/features/validation/schema", true);
    parser.setFeature( "http://apache.org/xml/features/validation/schema-full-checking", true);
    if (noNamespaceSchemaLocation!=null) {
    parser.setProperty(
    "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
    noNamespaceSchemaLocation);
    if (schemaLocation!=null) {
    parser.setProperty(
    "http://apache.org/xml/properties/schema/external-schemaLocation",
    schemaLocation);
    Also, as DrClap pointed out, for the schema location I use URIs.
    Please let me know if you got the jaxp schemaLocation property to work and how you did it.

  • Problem validating XML with XSD

    Hi everyone. I have an xsd schema and I want to validate some XML doc with the schema using SAX parser.
    The user make the xml and then upload it to the server.
    I want to enable client side validation but, for security reasons, I want also to validate this document when it's uploaded to the server.
    The schema called ContentSchema.xsd
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
         targetNamespace="www.mysite.com/Content" xmlns="www.mysite.com/Content">
         <xs:element name="content">
              <xs:complexType>
    A document produced by the client starts in this way:
    <?xml version="1.0" encoding="UTF-8"?>
    <p:content xmlns:p="www.mysite.com/Content" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="www.mysite.com/Content ContentSchema.xsd">
    in this way users can validate the XML doc before uploading. If the XSD is in the same folder of the uploaded XML the validation is ok.
    The problem is that, on the server, I've stored the xsd file in a folder and I want the SAX parser to use this xsd to validate the XML. Even I pass the complete URI of the file to the parser, it won't work:
    SAXParserFactory spf = SAXParserFactory.newInstance();
              spf.setValidating(true);
              spf.setNamespaceAware(true);
              spf.setFeature("http://apache.org/xml/features/validation/schema",true);
              spf.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
              SAXParser sp=spf.newSAXParser();
              sp.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", schemaURL );
    I set the schemURL with setProperty method but it's like the parser is looking for the XSD in the URL declared in the XML doc and not in the URI I specify. Anyone can help me?
    Thank you very much

    You will have to associate the schema with the namespace, like in your xsi:schemaLocation attribute.
    Try something like this:
    sp.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", "www.mysite.com/Content "+schemaURL);

  • Validating xml with external schema

    Hi,
    I want to validate a xml against an external schema using java and the xml WILL NOT contain any reference to the schema. Any help in the matter is most welcome.
    A typical example of such an xml is given below:
    <Envelope >
    <Body>
    " Some content here"
    </Body>
    </Envelope>
    I used the following code but it did not validate the xml.It simply parsed.
    public class TestParser {
         public static void main(String[] args) {
              final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
              final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
              try {
                   SAXParserFactory saxpfactory = SAXParserFactory.newInstance();
                   saxpfactory.setNamespaceAware(true);//
                   saxpfactory.setValidating(true);//
                   SAXParser parser = saxpfactory.newSAXParser();
                   parser.setProperty(JAXP_SCHEMA_LANGUAGE, "http://www.w3.org/2001/XMLSchema");//
                   parser.setProperty(JAXP_SCHEMA_SOURCE, "http://www.w3.org/2001/06/soap-envelope");//
                   parser.parse(new File("C:\\TEMP\\request.xml"), new DefaultHandler());
              } catch (FileNotFoundException fileNotFoundException) {
                   fileNotFoundException.printStackTrace();
              } catch (IOException ioException) {
                   ioException.printStackTrace();
              } catch (SAXException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              } catch (ParserConfigurationException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              System.out.println("exiting main ");
    Regards

    In the schema root element xs:schema add namespace declaration.
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    In the XML document root element add xmlns:xsi and xsi:noNamespaceSchemaLocation attributes.
    <root_element xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file://c:/testing.xsd">

  • How to validate an XML file with XSD Schema on JDK 1.4

    Hi
    I'm looking for samples how to validate xml files with xsd schema using jsdk 1.4
    Thank you.

    This is how.
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.dom.DOMResult;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.validation.Schema;
    import javax.xml.validation.SchemaFactory;
    import javax.xml.validation.Validator;
    DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
    dbfac.setNamespaceAware(true);
    SchemaFactory factory1 = SchemaFactory
                        .newInstance("http://www.w3.org/2001/XMLSchema");
    Schema schema = factory1.newSchema(new File("person.xsd"));
    dbfac.setSchema(schema);
    DocumentBuilder dbparser1 = dbfac.newDocumentBuilder();
    Document doc1 = dbparser1.parse(new File("person.xml"));
    Validator validator1 = schema.newValidator();
    DOMSource dm1 = new DOMSource(doc1);
    DOMResult domresult1 = new DOMResult();
    validator1.validate(dm1, domresult1);

  • Catch all error information while validating xml content with xsd schema

    Hi experts,
    I created a java mapping to validating the input xml content with xsd schema (schema validation). What I want is to catch all error message to the xml not just the first error. I used SAXParser in sapxmltoolkit.jar to do the schema validation. The below is a part of my java mapping.
    XMLReader parser = XMLReaderFactory.createXMLReader("com.sap.engine.lib.xml.parser.SAXParser");
    parser.setFeature( "http://xml.org/sax/features/validation" ,  true);
    parser.setFeature( "http://apache.org/xml/features/validation/schema" , true);
    parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");          parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",this.getClass().getClassLoader().getResourceAsStream(schema)); // schema is my schema name
    parser.setErrorHandler(new ParseErrorHandler()); // ParseErrorHandler is my own ErrorHandler which extends DefaultHandler
    parser.parse(new InputSource(new ByteArrayInputStream(sinput.getBytes())));
    // In error handler, I comment all code so as not to throw any exception
    public class ParseErrorHandler extends DefaultHandler
         public void error(SAXParseException e) throws SAXException
              // sSystem.out.println("Error" + e.getMessage());
              // throw e;
         public void fatalError(SAXParseException e)
              // throw e;
              // System.out.println("SAP Fatal Error" + e.getMessage());
    Unfortunately the program always stopped while catching the first error. Check the below log.
    com.sap.engine.lib.xml.parser.NestedSAXParserException: Fatal Error: com.sap.engine.lib.xml.parser.ParserException:
    ERRORS :
    cvc-simple-type : information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' is not valid, because it's value does not satisfy the constraints of facet 'minLength' with value '1'.
    cvc-data : information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' is is not valid with respoct to the corresponding simple type definition.
    cvc-element : element information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' is associated with invalid data.
    cvc-element : element information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]' is not valid with respect to it's complex type definition..
    cvc-element : element information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]' is not valid with respect to it's complex type definition..
    cvc-element : element information item '/:ShipNotice[1]/:Header[1]/:To[1]' is not valid with respect to it's complex type definition..
    cvc-element : element information item '/:ShipNotice[1]/:Header[1]' is not valid with respect to it's complex type definition..
    cvc-element : element information item '/:ShipNotice[1]' is not valid with respect to it's complex type definition..
    -> com.sap.engine.lib.xml.parser.ParserException:
    I tried using Xerces and JAXP to do validation, the same error happened. I have no idea on this. Does xi has its own error handler logic? Is there any body can make me get out of this?
    Thanks.

    <h6>Hi experts,
    <h6>
    <h6>I created a java mapping to validating the input xml content with xsd schema (schema validation). What I want is to catch all <h6>error message to the xml not just the first error. I used SAXParser in sapxmltoolkit.jar to do the schema validation. The below <h6>is a part of my java mapping.
    <h6>XMLReader parser = XMLReaderFactory.createXMLReader("com.sap.engine.lib.xml.parser.SAXParser");
    <h6>parser.setFeature( "http://xml.org/sax/features/validation" ,  true);
    <h6>parser.setFeature( "http://apache.org/xml/features/validation/schema" , true);
    <h6>parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");          <h6>parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",this.getClass().getClassLoader().getResourceAsStream(schema)); <h6>// schema is my schema name
    <h6>parser.setErrorHandler(new ParseErrorHandler()); // ParseErrorHandler is my own ErrorHandler which extends Default Handler
    <h6>parser.parse(new InputSource(new ByteArrayInputStream(sinput.getBytes())));
    <h6>
    <h6>// In error handler, I comment all code so as not to throw any exception
    <h6>public class ParseErrorHandler extends DefaultHandler
    <h6>{
    <h6>     public void error(SAXParseException e) throws SAXException
    <h6>     {
    <h6>          // sSystem.out.println("Error" + e.getMessage());
    <h6>          // throw e;
    <h6>     }
    <h6>
    <h6>     public void fatalError(SAXParseException e)
    <h6>     {
    <h6>          // throw e;
    <h6>          // System.out.println("SAP Fatal Error" + e.getMessage());
    <h6>
    <h6>     }
    <h6>
    <h6>}
    <h6>
    <h6>Unfortunately the program always stopped while catching the first error. Check the below log.
    <h6>
    <h6>com.sap.engine.lib.xml.parser.NestedSAXParserException: Fatal Error: com.sap.engine.lib.xml.parser.ParserException:
    <h6>ERRORS :
    <h6>cvc-simple-type : information item <h6>'/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' <h6>is not valid, because it's value does not satisfy the constraints of facet 'minLength' with value '1'.
    <h6>cvc-data : information item <h6>'/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' <h6>is is not valid with respoct to the corresponding simple type definition.
    <h6>cvc-element : element information item <h6>'/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' <h6>is associated with invalid data.
    <h6>cvc-element : element information item <h6>'/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]' <h6>is not valid with respect to it's complex type definition..
    <h6>cvc-element : element information item <h6>'/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]' <h6>is not valid with respect to it's complex type definition..
    <h6>cvc-element : element information item <h6>'/:ShipNotice[1]/:Header[1]/:To[1]' <h6>is not valid with respect to it's complex type definition..
    <h6>cvc-element : element information item <h6>'/:ShipNotice[1]/:Header[1]' <h6>is not valid with respect to it's complex type definition..
    <h6>cvc-element : element information item '/:ShipNotice[1]' is not valid with <h6>respect to it's complex type definition..
    <h6> -> com.sap.engine.lib.xml.parser.ParserException:
    <h6>
    <h6>
    <h6>I tried using Xerces and JAXP to do validation, the same error happened. I have no idea on this. Does xi has its own error <h6>handler logic? Is there any body can make me get out of this?
    <h6>Thanks.

  • Binding Xml file with Xsd Schema

    Hello
    everybody there.
    I am trying to make an application where word files are converted into xml.
    For that i have used org.exolab.castor and org.apache.poi.hwpf.
    Now the problem is that i was able to generate the xml file from word, but when i am binding it with XMLSchema.xsd following error is coming.
    java.lang.IllegalArgumentException: getSimpleType: the simple type 'formChoice' is not a built-in type as defined in XML Schema specification.
         at org.exolab.castor.xml.schema.Schema.getSimpleType(Schema.java:1289)
         at org.exolab.castor.xml.schema.Schema.addSimpleType(Schema.java:583)
         at org.exolab.castor.xml.schema.reader.SchemaUnmarshaller.endElement(SchemaUnmarshaller.java:643)
         at org.exolab.castor.xml.schema.reader.Sax2ComponentReader.endElement(Sax2ComponentReader.java:198)
         at org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1392)
         at org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator.java:1550)
         at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1149)
         at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
         at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
         at org.exolab.castor.builder.SourceGenerator.generateSource(SourceGenerator.java:430)
         at org.exolab.castor.builder.SourceGenerator.generateSource(SourceGenerator.java:485)
         at TempHwpf.<init>(TempHwpf.java:35)
         at TempHwpf.main(TempHwpf.java:44)the code for binding my xml file with xsd schema is as under:-
    SourceGenerator sourcegen = new SourceGenerator();
    sourcegen.getVersion();
    System.out.println(sourcegen.getVersion());
    sourcegen.generateSource("XMLSchema.xsd","packagename");I have checked XMLSchema.xsd file, in that formChoice is already defined, than also error is coming.
    can anyone help me out. first i thought that XMLSchema.xsd which i have is not proper, but i downloaded it again from w3c.org,
    than also same error is shown.
    please help me out.
    waiting for reply.
    milind

    Please do not double-post. http://forum.java.sun.com/thread.jspa?threadID=5134447&tstart=0
    Then use Stax (Woodstock) or Saxon.
    - Saish

  • How to validate xml file with XSD schema ??  in JDK1.4.2

    How to validate xml file with XSD schema ?? in JDK1.4.2
    i dont want to use new Xerec Jar ...
    Suggest option ...

    Please do not double-post. http://forum.java.sun.com/thread.jspa?threadID=5134447&tstart=0
    Then use Stax (Woodstock) or Saxon.
    - Saish

  • Issue in Store XML into Schema generated tables and Validation XML against registered schema.

    Hello friends,
    I am facing some problem when store xml into generated tables from registered schema.
    This is my Schema
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.abc.inf.in/test" targetNamespace="http://www.abc.inf.in/test" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:include schemaLocation="abc.xsd"/>
      <xs:element name="project" type="student">
      <xs:annotation>
      <xs:documentation> This is a Documentation</xs:documentation>
      </xs:annotation>
      </xs:element>
    </xs:schema>
    -- This is my xml document
    <project versao="2.00" xmlns="http://www.abc.inf.in/test">
      <test xmlns="http://www.abc.inf.in/test">
      <intest version="2.00" Id="testabc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  >
      <ide>
      <cUF>35</cUF>
      <cNF>59386422</cNF>
      <natOp>this is post</natOp>
      <indPag>1</indPag>
      <mod>55</mod>
      <serie>1</serie>
      </ide>............
    Not giving full because it's too long.
    1. I Successfully registered Schema into database
    2. Then i generate table from registered Schema
    2. In my java code i validated XML document against Schema and it's successfully validate.
    3. But when i stored this XML into this generated table it's give me error
       Like :
    INSERT INTO XMLTABLE
    VALUES
    (XMLTYPE(bfilename('MYDIR','testabc.xml'),NLS_CHARSET_ID('AL32UTF8')))
    Error report:
    SQL Error: ORA-31061: XDB error: XML event error
    ORA-19202: Error occurred in XML processing
    LSX-00333: literal "94032000" is not valid with respect to the pattern
    And i have to store this xml into this tables so what i have to do ?

    Thanks for your reply odie_63.
    I got this my error solution. My XML document is not well structured based on my registered XML Schema.
    Means In My XML Document there are some invalid value and that not match my schema pattern so it's gives this error
    SQL Error: ORA-31061: XDB error: XML event error
    ORA-19202: Error occurred in XML processing
    LSX-00333: literal "94032000" is not valid with respect to the pattern
    For Solution we have two ways
    1. I have changed this literal "94032000" value in my xml file then save it.
    2.
    - We have to delete this schema then
    - we have to change Schema pattern for particular element
    like :--
    <xs:restriction base="xs:string">
      <xs:whiteSpace value="preserve"/>
      <xs:pattern value="[0-9]{3}"/>
    </xs:restriction>
    - then store xml into database it works..
    Thanks.

  • Does XDB supports validating xml against multiple schemas?

    The XMLType has some methods for validating an xml documents against a schema, e.g., SCHEMAVALIDATE, etc.. does XDB support validating xml against multiple schemas (Just like what JAXP or Xerces have done)? Or what's the current situation about this issue? thanks.

    did you try using the import schema element instead of the include elemnt?

  • Schema Validation on attributes of an element in XML againt XSD schema

    Hi,
    I had generated artifact java classes from XSD schema file.Now i am validatiing one sample XML document by using these classes in JAXB.The XML document is validated successfully.but only elements are validated ,but not attributes of that elements.for example ,i am giving wrong element which is not defined inside the schema file,it throws validation error as expected ,whereas validation against wrong attributes of elements in XML it is not working anyway,it does not throw any validation errors,but it should throw validation errors.kindly help me to solve this issue.
    Here The sample validation code snippets :
    import javax.xml.bind.ValidationEvent;
    import javax.xml.bind.ValidationEventHandler;
    import javax.xml.bind.ValidationEventLocator;
    public class MyEventHandler implements ValidationEventHandler{
         public boolean handleEvent(ValidationEvent ve) {
              if (ve.getSeverity()==ValidationEvent.FATAL_ERROR ||
                        ve .getSeverity()==ValidationEvent.ERROR){
                   ValidationEventLocator locator = ve.getLocator();
                   //Print message from valdation event
                   System.out.println("Invalid booking document: "
                             + locator.getURL());
                   System.out.println("Error: " + ve.getMessage());
                   //Output line and column number
                   System.out.println("Error at column " +
                             locator.getColumnNumber() +
                             ", line "
                             + locator.getLineNumber());
              return true;
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    unmarshaller.setEventHandler(new MyEventHandler());

    Here is my analagous 'strange' behavior. I am jaxb processing and then marshalling generated classes to XML ( following the simple Sun 'PurchaseOrder' example )
    1. This works:
    <xsd:schema....>
    <xsd:complextType name = "myName">
    <xsd:attribute name='name1'>
    </xsd:complextType>
    </xsd:schema>
    2. This doesn't:
    <xsd:schema....>
    <xsd:complextType name = "myName">
    <xsd:attribute name='name1'/>
    <xsd:attribute name='name2'/>
    </xsd:complextType>
    </xsd:schema>
    That is, using more than one attribute line within this simple complex type causes nothing to be marshalled to XML.
    Ideas?

  • Error while Validating xml against a schema using jaxp

    Hi All,
    Following code validates xml against a schema using JAXP .It gives SAXNotRecognizedException error when you run the program.
    static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
    static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
    SAXParserFactory myFactory = SAXParserFactory.newInstance();
    myFactory.setNamespaceAware(true);
    myFactory.setValidating(true);
    javax.xml.parsers.SAXParser parser;
    String filename = "C:/Note.xml";
    File xmlFile = new File(filename);
    try
         DefaultHandler handler = new DefaultHandler();
         parser = myFactory.newSAXParser();
         parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
         parser.parse(xmlFile, handler);
    catch (ParserConfigurationException e)
         // TODO Auto-generated catch block
         e.printStackTrace();
    catch (SAXException e)
         // TODO Auto-generated catch block
         e.printStackTrace();
    catch (IOException e)
         // TODO Auto-generated catch block
         e.printStackTrace();
    Error Details :
    org.xml.sax.SAXNotRecognizedException: http://java.sun.com/xml/jaxp/properties/schemaLanguage
         at org.apache.xerces.framework.XMLParser.setProperty(XMLParser.java:1682)
         at org.apache.xerces.parsers.SAXParser.setProperty(SAXParser.java:770)
         at org.apache.xerces.jaxp.SAXParserImpl.setProperty(SAXParserImpl.java:183)
    How do i fix the above mentioned problem ?
    Thanks in Advance.
    Ansh

    Validate with the JAXP DOMParser instead of the JAXP SAXParser.
    To validate with a SAXParser use the xerces SAXParser.
    thanks,
    Deepak

  • Validate XML with XSD

    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    with the partitioning, real application clusters, olap, data mining
    and Real Application Testing options
    Working with relational tables containing clob type columns (no XMLDB available) I'm not able to set up a simple validation example as below (supposed to return 1 confirming a successful validation).
    declare
      xmldoc xmltype;
      sb_xml xmltype;
      valid_ number;
      xmlxsd varchar2(4000) := q'~<?xml version="1.0" ?>
                                  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
                                  <xs:element name="greeting" type="xs:string" />
                                  </xs:schema>~';
      xmlxml varchar2(32767) := q'~<?xml version="1.0" ?><greeting>"HELLO !"</greeting>~';
    begin
      xmldoc := xmltype(xmlxml);
      sb_xml := xmldoc.createschemabasedxml();
      valid_ := sb_xml.isschemavalid(xmlxsd);
      dbms_output.put_line('IsSchemaValid (0=false,1=true): ' || to_char(valid_));
    end;Thanks in advance for any kind of help provided
    Etbin

    no XMLDB availablenot sure if it will work without xmldb, but you might try to use java for schema validation:
    SQL> CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "SchemaUtil"
      2  as
      3
      4  import oracle.xml.parser.schema.*;
      5  import oracle.xml.parser.v2.*;
      6  import oracle.sql.CHAR;
      7  import java.io.*;
      8
      9  public class SchemaUtil
    10  {
    11     public static String validation(CHAR xml, CHAR xsd)
    12     throws Exception
    13     {
    14        //Build Schema Object
    15        XSDBuilder builder = new XSDBuilder();
    16        byte [] docbytes = xsd.getBytes();
    17        ByteArrayInputStream in = new   ByteArrayInputStream(docbytes);
    18        XMLSchema schemadoc = (XMLSchema)builder.build(in,null);
    19        //Parse the input XML document with Schema Validation
    20        docbytes = xml.getBytes();
    21        in = new ByteArrayInputStream(docbytes);
    22        DOMParser dp  = new DOMParser();
    23        // Set Schema Object for Validation
    24        dp.setXMLSchema(schemadoc);
    25        dp.setValidationMode(XMLParser.SCHEMA_VALIDATION);
    26        dp.setPreserveWhitespace (true);
    27        StringWriter sw = new StringWriter();
    28        dp.setErrorStream (new PrintWriter(sw));
    29        try
    30        {
    31           dp.parse (in);
    32           sw.write("The input XML parsed without errors.\n");
    33        }
    34        catch (XMLParseException pe)
    35        {
    36             sw.write("Parser Exception: " + pe.getMessage());
    37          }
    38        catch (Exception e)
    39          {
    40             sw.write("NonParserException: " + e.getMessage());
    41          }
    42          return sw.toString();
    43     }
    44   }
    45  /
    Java created.
    SQL>
    SQL> create or replace function schemavalidation(xml in varchar2,xsd in varchar2)
      2  return varchar2 is language java name 'SchemaUtil.validation(oracle.sql.CHAR,oracle.sql.CHAR)
      3                   returns java.lang.String';
      4  /
    Function created.
    SQL>
    SQL> select schemavalidation('<?xml version="1.0" ?><greeting>"HELLO !"</greeting>',
      2                           '<?xml version="1.0" ?>
      3                          <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      4                          <xs:element name="greeting" type="xs:string" />
      5                          </xs:schema>') schemavalidation from dual
      6  /
    SCHEMAVALIDATION
    The input XML parsed without errors.
    SQL>

  • WS-I validation failes with imported schema

    I'm getting the following error from the WS-I validation checker (Basic Profile 1.1):
    faultCode=INVALID_WSDL: Unable to determine namespace of 'messages:SigReplyMessage'.:
    Any idea what I'm doing wrong?
    My wsdl file looks like this:
    <definitions targetNamespace="urn:S3SignatureGenerator"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:tns="urn:S3SignatureGenerator"
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
    xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
    <types>
    <xsd:schema>
    <xsd:import id="Messages.xsd"
    schemaLocation="../../XSDDocument/Messages.xsd"
    namespace="messages"/>
    </xsd:schema>
    </types>
    <message name="ReturnSignature">
    <part name="SigAndExp" type="messages:SigReplyMessage"/>
    </message>
    <message name="RequestSignature">
    <part name="Keys" type="messages:SigRequestMessage"/>
    </message>
    <portType name="SigGenerator">
    <operation name="GetSignature">
    <input message="tns:RequestSignature"/>
    <output message="tns:ReturnSignature"/>
    <fault name="sigFault" message="tns:SigFault"/>
    </operation>
    </portType>
    <message name="SigFault">
    <part name="faultMessage" element="string"/>
    </message>
    <binding name="SigGenSoapHttp" type="tns:SigGenerator">
    <soap:binding style="document"
    transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="GetSignature">
    <soap:operation soapAction="urn:S3SignatureGenerator/GetSignature"/>
    <input>
    <soap:body use="literal" parts="SecretKey PublicKey"/>
    </input>
    <output>
    <soap:body use="literal" parts="Signature"/>
    </output>
    <fault name="sigFault">
    <soap:body use="literal" parts="SecretKey PublicKey"/>
    </fault>
    </operation>
    </binding>
    <service name="SignatureGenerationService">
    <port name="SigGenSoapHttpPort" binding="tns:SigGenSoapHttp">
    <soap:address location="tbd"/>
    </port>
    </service>
    </definitions>
    Messages.xsd looks like this:
    <?xml version="1.0" encoding="windows-1252" ?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.example.org"
    targetNamespace="http://www.example.org"
    elementFormDefault="qualified">
    <xsd:complexType name="sigRequestMessage">
    <xsd:sequence>
    <xsd:element name="publicKey" type="string"/>
    <xsd:element name="privateKey" type="string"/>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="complexType1">
    <xsd:sequence>
    <xsd:element name="Signature" type="string"/>
    <xsd:element name="expiration" type="timeDate"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:schema>

    You need to distinguish between the namespace and the namespace prefix.
    Your WSDL imports Messages.xsd with namespace "messages",
    but the schema defines namespace "http://www.example.org".
    You should change the import to use the right namespace,
    then declare the messages prefix in your WSDL:
    <definitions ....
    xmlns:messages="http://www.example.org" >
    <xsd:import id="Messages.xsd"
    schemaLocation="../../XSDDocument/Messages.xsd"
    namespace="http://www.example.org"/>
    Mik

  • Error in XML Parsing  through Schema doc.

    I know this is not the correct group for XML related queries. I had posted the query in XML forum but could not get any reply. I have been in the forum and know this is very active forum.
    Please help if you can..
    Hi Friends,
    I am trying to validate XML file as per the defined schema document through JAXB parser.
    Following is my xml. schema and java class code.
    XML File*
    <?xml version="1.0"?>
    <notify xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="NotificationDetailsSchema.xsd">
    <notification>
    <alertname>Alert1</alertname>
    <deletable>Y</deletable>
    <descurl>Alert1URL</descurl>
    </notification>
    <notification>
    <alertname>Alert2</alertname>
    <deletable>Y</deletable>
    <descurl>Alert2URL</descurl>
    </notification>
    </notify>
    Schema file_
    <?xml version="1.0" encoding="windows-1252"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xsd:element name="notify">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="notification" maxOccurs="unbounded">
    <xsd:complexType mixed="true">
    <xsd:sequence>
    <xsd:element name="alertname">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="1"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="deletable">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="Y|N"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="descurl">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="1"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>
    Java Class_
    SAXSource source = new SAXSource (xmlInputSource);
    SchemaFactory sf = SchemaFactory.newInstance (XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = sf.newSchema(schemaFileObj);
    Validator validator = schema.newValidator ();
    validator.setErrorHandler (new ParserErrorHandler());
    validator.validate (source);
    I tried to execute the validation through stand along java class and it worked correctly.
    However when I added this class into my Fusion web application, I am getting following error.
    org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw 'Alert1'._
    Can you please help me to figure out this problem?
    Edited by: Jaykishan on Jul 20, 2011 10:04 AM

    earlier it was
    org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw 'USAVER'.anmd now it is
    org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw 'Alert1'.some problem in this Alert1 message is what i guess.. some parsing error.. look closely..
    i guess some of the xml characters are not rendered properly in forum software.. or it may be truncated.. so i believe something wrong which is not visible..

Maybe you are looking for