Validating against a DTD

Hello,
what do I have to do if I want to validate a XML file against a DTD ?
I use cpp-Version for NT and have set the flags, but I didn't get an error-message for a wrong xml-file ?!

Was my fault. It worked fine !!
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by R|diger Brand ([email protected]):
Hello,
what do I have to do if I want to validate a XML file against a DTD ?
I use cpp-Version for NT and have set the flags, but I didn't get an error-message for a wrong xml-file ?!<HR></BLOCKQUOTE>
null

Similar Messages

  • Got exception when validating against a DTD

    We are using the XML Parser for Java v2.
    We created an instance of DOMParser, called parseDTD with a valid dtd file and called getDocType to obtain a handle to the DTD object.
    Then, we created a SAXParser and called setDocType(myDTD), where myDTD in the step above and called setValidationMode(true)
    We then use the SAXParser instance to parse an XML document that contains errors and we got the following exception:
    java.lang.ArrayIndexOutOfBoundsException: 101
    at oracle.xml.parser.v2.XMLError.error(XMLError.java:103)
    at oracle.xml.parser.v2.XMLError.error(XMLError.java:152)
    at oracle.xml.parser.v2.ValidatingParser.pushState(ValidatingParser.java:786)
    at oracle.xml.parser.v2.NonValidatingParser.parseElement(NonValidatingParser.java:913)
    at oracle.xml.parser.v2.ValidatingParser.parseRootElement(ValidatingParser.java:98)
    at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:201)
    at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:106)
    We don't get this exception if we use small files. We only get this if we use slightly larger files (>10000 lines)
    What is causing this exception? Any work arounds? Thanks.

    Was my fault. It worked fine !!
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by R|diger Brand ([email protected]):
    Hello,
    what do I have to do if I want to validate a XML file against a DTD ?
    I use cpp-Version for NT and have set the flags, but I didn't get an error-message for a wrong xml-file ?!<HR></BLOCKQUOTE>
    null

  • XML validation against a DTD

    Is there any one that can help me to :
    1- validate the well-formedness of the xml
    2- validate it against a DTD
    Thanks

    read the JAXP, SAX, DOM section of the tutorial:
    http://java.sun.com/webservices/docs/1.0/tutorial/doc/JavaWSTutorialTOC.html

  • Validating against a DTD specified externally

    Hi all,
    I don't know if this is possible (well anything is possible):
    I would like to validate an XML file from a DTD that I specify. The problem that I have is that the XML is generated by an external system and it can be deployed either on a unix or windows architecture.
    I load the XML from file located on either architecture and I want to control the location on either system where the DTD is kept and if possible tell the validator what DTD to use. I am having problems using relative paths when specifying the DTD in the XML and the company doesn't want to use an external public URI.
    I am using Java 1.4 and SAX 2.0 . Any pointers or help would be very much appreciated [code is even better ;-)]

    Hi,
    I cant seem to make the EntityResolver work properly. I was tasked to validate a lot of XML files but they do not have a DOCTYPE entity because the location of the dtd is configurable.
    i have stripped down the xml to only contain the root for brevity of testing but i am still stuck. the xml is this:
    <?xml version="1.0" encoding="utf-8"?>
    <ngui full="f" r="f">
    </ngui>and my validation code is this
    public class SimpleXMLValidator {
      public boolean validate(String xmlFilePath, String schemaFilePath){
            boolean validXML = true;
            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",schemaFilePath);
            try {
                DocumentBuilder builder = factory.newDocumentBuilder();
                ExternalResolver er = new ExternalResolver();
                er.addURL(schemaFilePath);
                builder.setEntityResolver(er);
                builder.parse(new File(xmlFilePath));
            } catch (ParserConfigurationException e) {
                validXML = false;
                e.printStackTrace();
            } catch (SAXException e) {
                validXML = false;
                e.printStackTrace();
            } catch (IOException e) {
                validXML = false;
                e.printStackTrace();
            return validXML;
       private class ExternalResolver implements EntityResolver{
            private HashMap urlMap = null;
            public InputSource resolveEntity(String publicId, String systemId){
                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);
    }If I hardcode the DOCTYPE then the file passes through the validation. and printout the System.out that I placed in the entity resolver. However I am getting the following exceptions:
    * if I remove the hard-coded DOCTYPE (notice that the EntityResolver output line is not written)
    C:\APPS\Eclipse-ws\testbed\bin>java SimpleXMLValidator ..\testdata\ac3.xml  ..\testdata\ngui.dtd
    Warning: validation was turned on but an org.xml.sax.ErrorHandler was not
    set, which is probably not what is desired.  Parser will use a default
    ErrorHandler to print the first 10 errors.  Please call
    the 'setErrorHandler' method to fix this.
    Error: URI=file:C:/APPS/Eclipse-ws/testbed/bin/../testdata/ac3.xml Line=2: Document is invalid: no grammar found.
    Error: URI=file:C:/APPS/Eclipse-ws/testbed/bin/../testdata/ac3.xml Line=2: Document root element "ngui", must match DOCTYPE root "null".* if I uncomment the setAttribute calls:
    C:\APPS\Eclipse-ws\testbed\bin>java SimpleXMLValidator ..\testdata\ac3.xml  ..\testdata\ngui.dtd
    resolvedEntity:null and file:C:/APPS/Eclipse-ws/testbed/testdata/ngui.dtd
    org.xml.sax.SAXParseException: The markup in the document preceding the root element must be well-formed.
            at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
            at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
            at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
            at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
            at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
            at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source)
            at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
            at org.apache.xerces.impl.xs.opti.SchemaParsingConfig.parse(Unknown Source)
            at org.apache.xerces.impl.xs.opti.SchemaParsingConfig.parse(Unknown Source)
            at org.apache.xerces.impl.xs.traversers.XSDHandler.getSchemaDocument(Unknown Source)
            at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
            at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
            at org.apache.xerces.impl.xs.XMLSchemaLoader.processJAXPSchemaSource(Unknown Source)
            at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
            at org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown Source)
            at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
            at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
            at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
            at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
            at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
            at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
            at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
            at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
            at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
            at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
            at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
            at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
            at SimpleXMLValidator.validate(SimpleXMLValidator.java:61)
            at SimpleXMLValidator.main(SimpleXMLValidator.java:40)* the setAttributes is still active in the compiled class but this time I hardcoded the DOCTYPE again.
    C:\APPS\Eclipse-ws\testbed\bin>java SimpleXMLValidator ..\testdata\ac3.xml  ..\testdata\ngui.dtd
    resolvedEntity:null and file:C:/APPS/Eclipse-ws/testbed/testdata/ngui.dtd
    resolvedEntity:null and file:C:/APPS/Eclipse-ws/testbed/testdata/ngui.dtd
    org.xml.sax.SAXParseException: The markup in the document preceding the root element must be well-formed.
            at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
            at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
            at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
            at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
            at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
            at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source)
            at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
            at org.apache.xerces.impl.xs.opti.SchemaParsingConfig.parse(Unknown Source)
            at org.apache.xerces.impl.xs.opti.SchemaParsingConfig.parse(Unknown Source)
            at org.apache.xerces.impl.xs.traversers.XSDHandler.getSchemaDocument(Unknown Source)
            at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
            at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
            at org.apache.xerces.impl.xs.XMLSchemaLoader.processJAXPSchemaSource(Unknown Source)
            at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
            at org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown Source)
            at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
            at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
            at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
            at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
            at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
            at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
            at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
            at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
            at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
            at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
            at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
            at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
            at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
            at SimpleXMLValidator.validate(SimpleXMLValidator.java:61)
            at SimpleXMLValidator.main(SimpleXMLValidator.java:40)does anybody know what I am missing here? Thanks.
    ciao!
    [edit] This posting of mine looks horrible both on IE and Firefox because its HTML tags are all in the text. I posted this question in http://ramfree17.org/capsule/?p=38 which is hopefully more readable.

  • How to disable validation against DTD while unmarshalling

    Hi All
    I am relatively new to XML and JAXB. I have a tool that needs to run offline, however the XML documents that are being read in are automatically being validated against the DTD even though I have specified unmarshaller.setValidating(false). How can I completely diable validation while offline? Here is my code:
    context = JAXBContext.newInstance("my.xmlobjects.package");
    Unmarshaller u = context.createUnmarshaller();
    u.setValidating(false);
    testLog = (TestLog) u.unmarshal(new File("/path/to/my/file.xml"));
    I've also tried a suggestion I saw on another forum (note that I know nothing about SAX, I've been trying to make sense of the documentation):
    SAXParserFactory parserFactory = SAXParserFactory.newInstance();
    parserFactory.setValidating(false);
    SAXParser saxParser = parserFactory.newSAXParser();
    XMLReader xmlReader = saxParser.getXMLReader();
    EntityResolver entityResolver = new EntityResolver()
    public InputSource resolveEntity (String publicId, String systemId)
    return null;
    xmlReader.setEntityResolver(entityResolver);
    InputSource source = new InputSource(new FileInputStream("/path/to/my/file.xml");
    SAXSource saxSource = new SAXSource(xmlReader, source);
    context = JAXBContext.newInstance("my.xmlobjects.package");
    Unmarshaller u = context.createUnmarshaller();
    u.setValidating(false);
    testLog = (TestLog) u.unmarshal(saxSource);
    Both of these work when connected, but fail when disconnected from the internet. Is there an Oracle specific property that needs to be set here?
    Thanks
    Jeff

    Well you can create non validating parser programatically .
    http://edocs.bea.com/wls/docs100/xml/programming.html#wp1069856
    i.e.
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setValidating(false);
    Hope this helps.

  • Validating XML documents against a DTD

    Guys I am new to XML and I have this requirement to validate a XML document against a DTD.This validation has to be done through my java application.In short , a user enters a XML data thru a JSP form ,and moment he presses the SAVE button my java program should validate the XML data against a DTD and then display any error or else save the data into an Oracle table.
    I was wondering lot of program/utitlities must be available out there which will do the validation for me ,rather than me re-inventing the wheel.
    Please advice.
    Thanks
    Manohar.

    You should go through this to learn more on XML with Java :
    http://www.onjava.com/pub/a/onjava/excerpt/learnjava_23/index1.html
    You can check following how to to parse XML doc against a schema
    http://otn.oracle.com/sample_code/tech/java/codesnippet/xdk/SchemaValidation/SchemaValidation.html
    You should also look at chapter 4 of following doc for parsing XML using java :
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96621/toc.htm
    Chandar

  • XML validation against DTD.. Is it possible?

    Hello all,
    Sorry for what may be a trivial post, but I'll keep it short..
    According to the docs:
    "The Validate XML command will validate the XML against the schema defined in the XML file. This command on the context menu is disabled whenever an XML file does not have an XML namespace defined."
    I'm used to the XML editor retrieving a DTD from somewhere and validating it against that.. is it possible to do this in JDev?

    Unfortunately it's not. We only have support for validating against XML Schemas.
    Rob

  • Validating against dtd

    Hi,
    I am trying to parse an xml against a dtd, using SAX parser. The validation is proper..but i want to parse the entire file even if there is a mismatch in the middle of the xml document.
    say if there is an error at one particular element, the parser throws an exception and quits..but i want the parser to continue with the rest of the document..
    how can i achieve this functionality..
    thanks & regards

    Hi,
    I had put the try catch block, the exception was getting caught and the program was exiting...later i used the ErrorHandler class to handle the exceptions..
    and it is working fine if there is a saxparseexception..
    But if there is some fatal error in the xml file, the parser throws the exception and quits. Is there any way to catch the fatal error and still proceed with the parsing.
    Thanks & regards

  • XML validation against DTD

    Hi,
    I have an application that receives XML from an external source. The XML received does not have the XML version and the doc type declaration lines. I want to validate the XML against a DTD.
    One dirty way of doing this is to open the XML received and prepend the XML versions and doctype lines to it. And then parse the XML. But is it the right way to do it?
    What I would like to know is that does the XML parser provide any API which can tell it to validate an XML document against a certain DTD.

    Yes, there is an API to do this. You have to do something like this:
    DocumentBuilderFactory dbf          =DocumentBuilderFactory.newInstance();
    dbf.setValidating(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    XMLErrors eh = new XMLErrors(frame);
    db.setErrorHandler(eh);
    Document doc = db.parse(f);
    (where f is the XML file)
    In this example, the class XMLErrors is used as the ErrorHandler. XMLErrors extends the DefaultHandler class and provides the user with information about the various error levels. A call to the over-ridden "error" method notifies the user (using a Dialog box) that the document doesn't meet the DTD.
    Hope this helps.

  • How to parse XML against XSD,DTD, etc.. locally (no internet connection) ?

    i've searched on how to parse xml against xsd,dtd,etc.. without the needs of internet connection..
    but unfortunately, only the xsd file can be set locally and still there needs the internet connection for the other features, properties.
    XML: GML file input from gui
    XSD: input from gui
    javax.xml
    package demo;
    import java.io.File;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.xml.XMLConstants;
    import javax.xml.transform.Source;
    import javax.xml.transform.stream.StreamSource;
    import javax.xml.validation.Schema;
    import javax.xml.validation.SchemaFactory;
    import javax.xml.validation.Validator;
    import org.xml.sax.SAXException;
    public class Sample1WithJavaxXML {
         public static void main(String[] args) {
              URL schemaFile = null;
              try {
                   //schemaFile = new URL("http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd");
                   File file0 = new File("AppSchema-C01-v1_0.xsd");
                   schemaFile = new URL(file0.toURI().toString());
              } catch (MalformedURLException e1) {
                   // TODO Auto-generated catch block
                   e1.printStackTrace();
              //Source xmlFile = new StreamSource(new File("web.xml"));
              Source xmlFile = new StreamSource(new File("C01.xml"));
              SchemaFactory schemaFactory = SchemaFactory
                  .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
              //File file1 = new File("XMLSchema.dtd");
              //SchemaFactory schemaFactory = SchemaFactory
                   //.newInstance("javax.xml.validation.SchemaFactory:XMLSchema.dtd");
              Schema schema = null;
              try {
                   schema = schemaFactory.newSchema(schemaFile);
              } catch (SAXException e1) {
                   // TODO Auto-generated catch block
                   e1.printStackTrace();
              Validator validator = schema.newValidator();
              try {
                validator.validate(xmlFile);
                System.out.println(xmlFile.getSystemId() + " is valid");
              } catch (SAXException e) {
                System.out.println(xmlFile.getSystemId() + " is NOT valid");
                System.out.println("Reason: " + e.getLocalizedMessage());
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    }Xerces
    package demo;
    import java.io.File;
    import java.util.Date;
    import org.apache.xerces.parsers.DOMParser;
    public class SchemaTest {
         private String xmlFile = "";
         private String xsdFile = "";
         public SchemaTest(String xmlFile, String xsdFile) {
              this.xmlFile = xmlFile;
              this.xsdFile = xsdFile;
         public static void main (String args[]) {
              File file0 = new File("AppSchema-C01-v1_0.xsd");
              String xsd = file0.toURI().toString();
              SchemaTest testXml = new SchemaTest("C01.xml",xsd);
              testXml.process();
         public void process() {
              File docFile = new File(xmlFile);
              DOMParser parser = new DOMParser();
              try {
                   parser.setFeature("http://xml.org/sax/features/validation", true);
                   parser.setFeature("http://apache.org/xml/features/validation/schema", true);
                   parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
                             xsdFile);
                   ErrorChecker errors = new ErrorChecker();
                   parser.setErrorHandler(errors);
                   System.out.println(new Date().toString() + " START");
                   parser.parse(docFile.toString());
              } catch (Exception e) {
                   System.out.print("Problem parsing the file.");
                   System.out.println("Error: " + e);
                   System.out.println(new Date().toString() + " ERROR");
                   return;
              System.out.println(new Date().toString() + " END");
    }

    Thanks a lot Sir DrClap..
    I tried to use and implement the org.w3c.dom.ls.LSResourceResolver Interface which is based on the SAX2 EntityResolver.
    please give comments the way I implement it. Here's the code:
    LSResourceResolver Implementation
    import org.w3c.dom.ls.LSInput;
    import org.w3c.dom.ls.LSResourceResolver;
    import abc.xml.XsdConstant.Path.DTD;
    import abc.xml.XsdConstant.Path.XSD;
    public class LSResourceResolverImpl implements LSResourceResolver {
         public LSResourceResolverImpl() {
          * {@inheritDoc}
         @Override
         public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
              ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
              LSInput input = new LSInputImpl(publicId, systemId, baseURI);
              if ("http://www.w3.org/2001/xml.xsd".equals(systemId)) {
                   input.setByteStream(classLoader.getResourceAsStream(XSD.XML));
              } else if (XsdConstant.PUBLIC_ID_XMLSCHEMA.equals(publicId)) {
                   input.setByteStream(classLoader.getResourceAsStream(DTD.XML_SCHEMA));
              } else if (XsdConstant.PUBLIC_ID_DATATYPES.equals(publicId)) {
                   input.setByteStream(classLoader.getResourceAsStream(DTD.DATATYPES));
              return input;
    }I also implement org.w3c.dom.ls.LSInput
    import java.io.InputStream;
    import java.io.Reader;
    import org.w3c.dom.ls.LSInput;
    public class LSInputImpl implements LSInput {
         private String publicId;
         private String systemId;
         private String baseURI;
         private InputStream byteStream;
         private String stringData;
         public LSInputImpl(String publicId, String systemId, String baseURI) {
              super();
              this.publicId = publicId;
              this.systemId = systemId;
              this.baseURI = baseURI;
         //getters & setters
    }Then, here's the usage/application:
    I create XMLChecker class (SchemaFactory implementation is Xerces)
    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;
    import javax.xml.XMLConstants;
    import javax.xml.stream.FactoryConfigurationError;
    import javax.xml.transform.Source;
    import javax.xml.transform.stream.StreamSource;
    import javax.xml.validation.Schema;
    import javax.xml.validation.SchemaFactory;
    import javax.xml.validation.Validator;
    import org.xml.sax.ErrorHandler;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import abc.xml.XsdConstant.Path.XSD;
    public class XMLChecker {
         private ErrorMessage errorMessage = new ErrorMessage();
         public boolean validate(String filePath){
              final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
              List<Source> schemas = new ArrayList<Source>();
              schemas.add(new StreamSource(classLoader.getResourceAsStream(XSD.XML_SCHEMA)));
              schemas.add(new StreamSource(classLoader.getResourceAsStream(XSD.XLINKS)));
              schemas.add(new StreamSource(classLoader.getResourceAsStream("abc/xml/AppSchema.xsd")));
              SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
              schemaFactory.setResourceResolver(new LSResourceResolverImpl());
              try {
                   Schema schema = schemaFactory.newSchema(schemas.toArray(new Source[schemas.size()]));
                   Validator validator = schema.newValidator();
                   validator.setErrorHandler(new ErrorHandler() {
                        @Override
                        public void error(SAXParseException e) throws SAXException {
                             errorMessage.setErrorMessage(e.getMessage());
                             errorMessage.setLineNumber(e.getLineNumber());
                             errorMessage.setColumnNumber(e.getLineNumber());
                             throw e;
                        @Override
                        public void fatalError(SAXParseException e) throws SAXException {
                             errorMessage.setErrorMessage(e.getMessage());
                             errorMessage.setLineNumber(e.getLineNumber());
                             errorMessage.setColumnNumber(e.getLineNumber());
                             throw e;
                        @Override
                        public void warning(SAXParseException e) throws SAXException {
                             errorMessage.setErrorMessage(e.getMessage());
                             errorMessage.setLineNumber(e.getLineNumber());
                             errorMessage.setColumnNumber(e.getLineNumber());
                             throw e;
                   StreamSource source = new StreamSource(new File(filePath));
                   validator.validate(source);
              } catch (SAXParseException e) {
                   return false;
              } catch (SAXException e) {
                   errorMessage.setErrorMessage(e.getMessage());
                   return false;
              } catch (FactoryConfigurationError e) {
                   errorMessage.setErrorMessage(e.getMessage());
                   return false;
              } catch (IOException e) {
                   errorMessage.setErrorMessage(e.getMessage());
                   return false;
              return true;
         public ErrorMessage getErrorMessage() {
              return errorMessage;
    }Edited by: erossy on Aug 31, 2010 1:56 AM

  • Validate XML against  one DTD

    Hello
    I have several XML files and into this XML files there is not th DTD call.
    i have another file, the DTD.
    There is any method or code example for, without modify the XML files for including the DTD call, validate the XML againts one DTD?
    thanks

    Alice (guest) wrote:
    : Hi! I have obtained the v2 parser for java and the one for
    plsql.
    : I want to validate xml documents against a DTD file provided
    by
    : another program. I can't find any sample code that does setDTD
    : for validation.
    : Can you tell me how it can be done, please?
    : Thanks in advance!
    The method to set the DTD is setDoctype().
    Stub code follows:
    // Test using InputSource
    parser = new DOMParser();
    parser.setErrorStream(System.out);
    parser.showWarnings(true);
    FileReader r = new FileReader(args[0]);
    InputSource inSource = new InputSource(r);
    inSource.setSystemId(createURL(args[0]).toString());
    parser.parseDTD(inSource, args[1]);
    dtd = (DTD)parser.getDoctype();
    r = new FileReader(args[2]);
    inSource = new InputSource(r);
    inSource.setSystemId(createURL(args[2]).toString());
    parser.setDoctype(dtd);
    parser.setValidationMode(true);
    parser.parse(inSource);
    doc = (XMLDocument)parser.getDocument();
    doc.print(new PrintWriter(System.out));
    Oracle XML Team
    http://technet.oracle.com
    Oracle Technology Network
    null

  • How to use Xerces to validate an XML file against a DTD

    Hi, can anybody tell me how to use Xerces to validate an XML file against a DTD. its urgent. post some sample code. it would be helpful for my project. isupposed to use SAX parser(Xerces)
    Thanx in advance

    Come on, I googled "xerces validate" and the first link is the Xerces FAQ:
    http://xerces.apache.org/xerces-j/faq-general.html
    And of course "how to validate" is a Xerces FAQ. Help yourself by doing a little research instead of waiting for other people.

  • Using XSL on XML validated against XSD

    Transforming XSD validated XMLType Data
    Re: example XSL in Chapter 6 that transforms XML with associated XSD schema definition (Oracle 9i XML Database Developer's Guide)
    I noted that this XSL uses only the "general" node identification functions (e.g., name() ) to access nodes in the <xsl:value-of select..>. I have also noted that standard XSL templates from other sections of the documentation, for example in Chapter 3 and in Appendix D, do not work with an XML which is validated against an XSD schema.
    Can anyone give me an example <xsl:value-of select..> that addresses a specific node in the "purchase order" example, like the shipTo, name, street -- or any other specific node. This is critical since there is always bound to be node-specific processing in any transformation, and this is not demonstrated by any example of XML which has been validated against an XSD.
    I have tried this endlessly on my own examples of XML w/XSD validation. Even if the value-of select="name(.)" tells you that the name of the node is "FooBar", you cannot use FooBar as a select test to do FooBar specific processing.
    Help?????

    Not quite understand your question. Can you send me the example doc?

  • XML validation against XSD

    Hi,
    Does Oracle 8i (Release 3) support XML validations against XSD? I know Oracle 9i (Release 2) supports XML validations against XSD.
    Also, Does Oracle support XML validations against XDR?
    Any info is appreciated.
    Thanks
    Pavan

    Validate with DOMParser or the SAXParser.

  • How can i validate an xml against an dtd which are both in a clob ?

    Hi,
    I think my question says it all. I would like to validate
    my xml which has been stored into a clob against a dtd
    also stored in a clob. It has to be done with the xdk for plsql.
    Regards,
    Geert.

    Hi,
    I think my question says it all. I would like to validate
    my xml which has been stored into a clob against a dtd
    also stored in a clob. It has to be done with the xdk for plsql.
    Regards,
    Geert.

Maybe you are looking for

  • Is anybody else having problems with itunes (10.6.3.25) and ipod touch (5.1.1)?

    Lately I've been having a ton of problems with iTunes and my iPod Touch (4th generation). Lots of error messages such as can't connect to itunes store, incompatible application, ipod detected but not identifiable, invalid response received from devic

  • Automated Reports

    I've created a report that I would like my BC site to email on a daily basis to my customer, so they see all the details of bookings. I am wondering if there are tags available tags Like {ReportID=1289} and/or {tag_booking id(tag_event}} that I can p

  • Linked pdfs from chm do not work in windows 8/explorer 11

    I get the x broken link in top right corner... I tried all the solutions from changing reader settings to IE settings... no luck. the chm links works fine when opened on windows 7 and the pdfs open in multi screen and epub output. This is definitely

  • Table USR01 and USR02

    Hi Can someone advise what is the difference between table USR01 and USR02 and is it possible for the 2 tables to have different number of records. Thank you.

  • Time Machine & Sound Files

    I Have and external disk in which I keep the exact copies of my cds, meaning 1444kbs sound files that ocupay a lot of space hence the external disk. I just bought a one tera Time Capsule to backup my macbook and this disc, I also woul like to back up