Validating xml with dtd

Hi,
         I have found a piece of code through google, to validate an xml file with an external dtd file. which is
           function validateDocument()
                xmlDocumentObject = new ActiveXObject("microsoft.XMLDOM")
                xmlDocumentObject.onreadystatechange = changeHandler
                xmlDocumentObject.load('C:\\My.xml')
            function changeHandler()
           and for that we need to a import i.e  #import "C:\WINDOWS\system32\msxml4.dll"
          here when i try to import "msxml4.dll" in Acrobat javascript (js) file, it is giving error, application exits.
           How can i import dll in Acrobat javascript to get some functionality, or if not
          What someother way to achieve this(To validate xml with dtd file).
         This is totally making me crazy, please someone help me on this issue.
thanks in advance.

thanks Leonard,
         But my problem is i have an xml(i created that using acrobat javascript)and a dtd file, i want validate xml file with that dtd, using acrobat or some other way.  How can i validate xml with dtd, please help me.

Similar Messages

  • HOW TO KNOW VALID XML WITH DTD ? WITHOUT PARSING  ?

    i am creating the xml file
    i need to validate the xml with DTD to confirm is it valid or not ?
    with out parsing...
    could you tell me how ?
    Durga

    without parsing u cant do it..

  • Validating XML with DTD ..... Urgent

    Hi all,
    I am using java 1.4
    I have to validate the XML file with the external DTD.
    Can anyone give me the code for that.
    DTD should be external.
    Thanks,
    Vinayak.

    Hello Vinayak,
    I'm kind of new to this but I thinik I saw what you're looking for in a program called Echo05 or Echo07 in chapter 5 of http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html.
    I think I was working on it Friday and basically you have to have your own DTD then when Echo echo's the output it will throw errors with vaugue messages about how messed up your DTD is.
    Regards,
    Bill

  • 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);

  • Regarding validating XML against DTD

    hello,
    In my project I am receiving xml via HTTP post request
    and this XML needs to be validated against a DTD in a remote server.
    e.g. assume the xml to be
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE PUSH SYSTEM "http:\\whatever:xx\whatever\sms.dtd">
    <PUSH ICP="Partenaire" ADM="UtilisateurChezPartenaire" VERSION="1.0">
    </PUSH>
    the java code uses Xerces parser
          DOMParser parser = new DOMParser();
          parser.setFeature("http://xml.org/sax/features/validation", true);
          parser.setProperty(
                             "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
                             "http:\\whatever:xx\whatever\sms.dtd"");
          parser.parse("c://localcopy/sms.xml");this Works fine.
    But in some case I receive xml file without any !DOCTYPE declaration
    (but is still needs to be validated against the same DTD as its mentioned in the business rules)
    in such case how can the XML be validated against the DTD.
    am I extected to add the
    <!DOCTYPE PUSH SYSTEM "http:\\whatever:xx\whatever\sms.dtd">
    to every XML via some XSLT script or is there a direct way of
    validating a xml that has no DOCTYPE reference to a DTD
    (the assumption is the DTD location is known beforehand)

    ok, i managed to solve the problem my self, using Transformer makes the job easier.
    here is the code for anyone who might run into the same problem.#
         public void whatEver(){
              try{
                   DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
                   DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
                   Document xmlDocument = dBuilder.parse(new FileInputStream("c://a.xml"));
                   DOMSource source = new DOMSource(xmlDocument);
                   //StringWriter writer = new StringWriter();
                   StreamResult result = new StreamResult("c://a.xml");
                   TransformerFactory tf = TransformerFactory.newInstance();
                   Transformer transformer = tf.newTransformer();
                   transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "./transformations/Push_Gateway.dtd");
                   //TransformerFactory transformerFactory = TransformerFactory.newInstance();
                   //Transformer newtransformer = transformerFactory.newTransformer();
                   transformer.transform(source, result);
              catch(Exception e){
                   e.printStackTrace();
         }the above code reads the a.xml file and adds/removes the DOCTYPE as specified in the transformer.setOutputProperty method and the same xml file is updated, this way different DTD could be referenced by the same xml and validated. this saves the process of adding/removing DOCTYPE via xslt.

  • Does IE/Firefox browser validate a give XML with DTD

    Hi,
    The following is my XML with an internal DTD and below that is the css
    <?xml version="1.0" ?>
    <!DOCTYPE INVENTORY
    <!ELEMENT INVENTORY (BOOK)+ >
    <!ELEMENT BOOK (NAME,PRICE)>
    <!ELEMENT NAME (#PCDATA)>
    <!ELEMENT PRICE (#PCDATA)>
    <!ELEMENT IMAGE EMPTY>
    >
    <?xml-stylesheet type="text/css" href="Inventory01.css"?>
    <INVENTORY>
    <BOOK>
         <NAME> 101 Thins to lie </NAME>
         <PRICE> 9494.03</PRICE>
         <IMAGE> TEST </IMAGE>
    </BOOK>
    <BOOK>
         <NAME> iT nEVER Gets Better </NAME>
         <PRICE> 44.43</PRICE>
    </BOOK>
    </INVENTORY>The following is the CSS file refered above.
    BOOK
         display:block;
         margin-top:12pt;
         font-size:10pt
    NAME
         display:block;
         margin-top:12pt;
         font-weight:bold;
         font-style:italic;
    PRICE
         display:block;
         margin-left:15pt;
    }I was expecting the browser to validate my XML and give me an error. Please tell me if the browsers validate XMLs? If yes, is there any issue with the above code.
    Thanks.
    Regards,
    Technoz

    I was expecting the browser to validate my XML and
    give me an error. Please tell me if the browsers
    validate XMLs?Try this experiment: Set up an XML that doesn't validate against its internal DTD. Then load it into a browser to see if the browser validates it or not.
    Oh wait, didn't you already try that experiment? What did you find out?

  • Validating XML with its DTD in JSP

    Is there a way to validate an XML file with its DTD, using a JSP ???
    If YES, then HOW???
    I hope my question is clear enough.
    Please help!!

    Thanks "Jleech",
    I am using a textarea in a JSP to input for an XML file. The JSP transfers the file to Web-Server, which also has XERCES installed. My question is how can u Validate this transfered XML file with its DTD. My problem is I don't to how to include that Validation program in JSP.?
    Could you still help???

  • Validating an xml with DTD external DTD

    Hi
    how can i validate my XML File with an external DTD ?
    thanks for your replies
    serge

    Hi,
    when you use the XML Library, the interface <b>if_ixml_parser</b> has a static method <b>set_validation( )</b> to activate and deactivate a DTD validation.
    There are the follow constants in the if_ixml_parser for the DTD validation-mode:
    <b>if_ixml_parser=>co_no_validation</b>
    Do not validate the XML-Document against the document type definition (DTD)
    <b>if_ixml_parser=>co_validate</b>
    Validate the XML-Document against the document type definition (DTD)
    <b>if_ixml_parser=>co_validate_if_dtd</b>
    Validate the XML-Document against the document type definition (DTD) if a DTD is specified. Otherwise parse the Document in non validating mode.
    see also the SAP online-help:
    <a href="http://help.sap.com/saphelp_webas610/helpdata/de/bb/5766b2dca511d4990b00508b6b8b11/content.htm">Interface if_ixml_parser</a>
    Regards
    Stefan

  • Validating XML with external dtd without doctype specified in xml

    Hi,
    I am very new to SAX, DOM and things..but I am really pulling my hair to find the soln., I have tried to search soln but I found many people asking same question but hardly anyone was satisfactory.
    My problem is that I have xml file without doctype specified in it, but I have dtd available on my system.
    I have tried to set MyEntityResolver which implements EntityResolver in documentBuilder but its only getting called (resolveEntity method of MyEntirtyResolver), only when I add doctype to the xml (which is not what I want) and not when there is no doctype in the xml. I have set "factory.setValidating(true)" and I also have errorHandler in place.
    But why EntityResolver is not invoked when its needed most. ie. when doctype is not available in xml ?...it complains that DOCTYPE must match root=null , which is obvious because no DOCTYPE in xml.
    code is as follows:
    please help me ..if anyone has any idea about this ....
    Main class is :
    public static void main(String args[]){
              Document document=null;
              ErrorHandler defaultHandler=new MyDefaultHandler();
              String xmlFile="note.xml";
              try{
                   System.out.println("Starting...");
                 boolean validXML = true;
                 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                 factory.setNamespaceAware(true);
                 factory.setValidating(true);
                 try {
                    ExternalResolver er = new ExternalResolver();
    // addURL is just a method which sets string in a map to be retrieved by resolveEntiy
                    er.addURL("D:\\SAXnDOM\\SAXProject\\note.dtd");
                    DocumentBuilder builder = factory.newDocumentBuilder();
                     builder.setEntityResolver(er);
                     builder.setErrorHandler(new MyDefaultHandler());
                    builder.parse(new File(xmlFile));
                 resolveEntity of ExternalResolver is as follows:
    public InputSource resolveEntity(String publicId, String systemId)
                   throws SAXException, IOException {
               System.out.println("********resolvedEntity:" +publicId +" and "+systemId +"******");
             if ( urlMap != null && urlMap.get(systemId)!= null ){
                 try {
                     return new InputSource(new FileReader(systemId));
                 } catch (FileNotFoundException e) {
                     System.out.println("[ERROR] Unable to load entity reference: " + systemId );
             return null;
    public void addURL(String filePath) throws MalformedURLException{
              addURL(new File(filePath).toURL());
         public void addURL(URL url) {
             if ( urlMap == null ){
                 urlMap = new HashMap();
             urlMap.put(url, null);
         }

    Its working.... its working ...
    problem was in resolveEntity, that stupid if condition was removed like this:
    public InputSource resolveEntity(String publicId, String systemId)
                   throws SAXException, IOException {
               System.out.println("********resolvedEntity:" +publicId +" and "+systemId +"******");
                try {
                     return new InputSource("D:\\SAXnDOM\\SAXProject\\note.dtd");
                 } catch (Exception e) {
                     System.out.println("[ERROR] Unable to load entity reference: " + systemId );
             return null;
         }Other change is (which I didnt like ) is that in my xml, I had written fake doctype like :
    <?xml version="1.0"?>
    <!DOCTYPE note SYSTEM "fakenote.dtd">
    <note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
    <Prashant>prdfjfdj</Prashant>
    </note> in above code fakenote.dtd doesnt exist anywhere ..its just to bypass that doctype:null error.
    So my guess is that EntityResolver overrides doctype in the xml and applies its own doctype (note.dtd in this case)
    But new proble comes...what if i dont want to add any doctype ..not even fake in xml ?
    Hope my stupid mistakes will find someone usefull..

  • Strange problem when validating XML agains DTD file.

    Dear experts,
    I'm write a simple code snippet that validates my XML file agains a given DTD.
    It allways report the following error:
    org.xml.sax.SAXParseException: The markup in the document preceding the root element must be well-formed.
         at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
         at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)Althought, my xml file is OK with Xmlspy.
    My code is:
    System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
                             "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          factory.setNamespaceAware(true);
          factory.setValidating(true);
          factory.setAttribute(
              "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
              "http://www.w3.org/2001/XMLSchema");
          factory.setAttribute(
              "http://java.sun.com/xml/jaxp/properties/schemaSource", SchemaUrl);
          DocumentBuilder builder = factory.newDocumentBuilder();
          Validator handler = new Validator();
          builder.setErrorHandler(handler);
          builder.parse(new java.io.FileInputStream(new java.io.File(XmlDocumentUrl)));And here are the xml file:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE capsule SYSTEM "c:/SampleFiles/capsule.dtd">
    <capsule>
         <header>
              <name>Capsule 1</name>
              <author>Author</author>
              <company>Company</company>
              <last-save-time>Fri Apr 01 14:59:21 GMT+07:00 2005</last-save-time>
              <description>description</description>
         </header>
         <datasets>
              <dataset type="input">
                   <name>dataset1</name>
                   <description></description>
                   <columns>
                        <column type="fromsource">
                             <name>partno</name>
                             <data-type>varchar</data-type>
                             <length>80</length>
                             <precision/>
                             <scale/>
                             <allow-null>false</allow-null>
                             <default-value/>
                        </column>
                        <column type="notfromsource">
                             <name>balanceonhand</name>
                             <data-type>integer</data-type>
                             <length/>
                             <precision/>
                             <scale/>
                             <allow-null>false</allow-null>
                             <default-value/>
                        </column>
                   </columns>
                   <rule>LET a=update; LET b=employye set salary = 100; print a + b</rule>
                   <!--output: update employee set salary = 100-->
                   <command>inmemory (getvalue_dataset("dataset1".rule))</command>
                   <params>
                        <param>
                             <name/>
                             <type/>
                        </param>
                   </params>
              </dataset>
         </datasets>
    </capsule>What I can do now? Change my xml file?
    Please provide some hints.
    Thanks in advance.

    I tried to remove the DOCTYPE, but the problem stayed the same.
    Thanks.

  • 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);

  • 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.

  • Validating XML Against DTD

    I'm relatively new to Java and I was just wondering what is the most effective way of comparing an XML document to its DTD to ensure the document is valid.
    Any advice would be appreciated.

    Thanks for the example but looks like SUN code is buggy when compiled?
    The method parse(InputStream, HandlerBase) in the type SAXParser is not applicable for the arguments (File, DefaultHandler)

  • Xmlparser.parse fails when parsing xml with dtd

    Has anybody used successfully called xmlparser.parse in PL/SQL
    to parse an xml file with a dtd? When I try I get the following
    error:
    ERROR at line 1:
    ORA-20100: Error occurred while parsing: Invalid argument
    ORA-06512: at "SYS.XMLPARSER", line 22
    ORA-06512: at "SYS.XMLPARSER", line 69
    ORA-06512: at line 6
    When I remove the dtd reference from the xml file it works.
    (I posted this question yesterday but no responses, so I'm
    trying again...)
    Thanks - Dana

    Please see:
    http://forums.oracle.com/forums/message.jsp?id=617954
    for the solution. Thanks.

  • Parsing XML with DTD residing in jar file

    Hi,
    I have problems using crimson parser for my program under JDK 1.4.0b2. It attempts to parse an xml file with SAX. The corresponding lies in a jar file in a different directory but reachable through the classpath. All I get is an exception.
    org.xml.sax.SAXParseException: Relative URI "my.dtd"; kann nicht ohne eine Dokument-URI aufgel�st werden.
    at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3121)
    at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3115)
    at org.apache.crimson.parser.Parser2.resolveURI(Parser2.java:2702)
    at org.apache.crimson.parser.Parser2.maybeExternalID(Parser2.java:2674)
    at org.apache.crimson.parser.Parser2.maybeDoctypeDecl(Parser2.java:1125)
    at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:489)
    at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
    at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:433)
    at org.xml.sax.helpers.XMLReaderAdapter.parse(XMLReaderAdapter.java:223)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:326)
    I used Xerces before and it worked fine. I already searched the community for that problem. All hints I found assume that xml file and dtd are in the same directory. Setting the systemId of the input source doesn't fix the problem.
    Is there anyone out there knowing what to do?
    Thanks,
    Thorsten

    Use a Resolver to map a PUBLIC name to a local name:
    <!DOCTYPE DOC PUBLIC "-//gaskin.de//XMLDOC 1.0//EN"
    "http://www.gaskin.de/dtd/xmldoc.dtd">
    public static register() {
       ClassLoader loader = Resolver.class.getClassLoader();
       registerCatalogEntry(
          "-//gaskin.de//XMLDOC 1.0//EN",
          "de/gaskin/resources/dtd/XMLDOC.DTD",
          loader);
    }

Maybe you are looking for