DTD validation

Hi All,
I am using Sax parser (jaxp1.1), I have directed to validate the xml using setValidating(true), even then it is not validating the data against DTD spec.
PLease let me know the possible things to be checked.
Thanks
Sathish

Hi , I am passing the handler of present class to the parser.
My Code looks like
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import java.util.*;
import java.io.*;
public class Stores extends DefaultHandler {
// Instance variables
Hashtable stores;
Hashtable storeInfo;
public Hashtable returnStores() {   
return stores;
public Hashtable getStoreInfo() {
String xmlFile = "Print.xml";
Stores wpInstance = new Stores();
DefaultHandler wpHandler = wpInstance;
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(true);
try {
SAXParser saxParser = factory.newSAXParser();
saxParser.parse(new File(xmlFile), wpHandler);
} catch (SAXParseException spe) {
System.err.println("\n ** Parsing error " + ", line " + spe.getLineNumber() +
", uri " + spe.getSystemId());
System.err.println(" " + spe.getMessage());
// Catch the contained Exception, if exist
Exception ex = spe;
if( spe.getException() != null) ex = spe.getException();
ex.printStackTrace();
} catch (SAXException sxe) {
Exception ex = sxe;
if (sxe.getException() != null) ex = sxe.getException();
ex.printStackTrace();
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
return wpInstance.returnStores();
// Buffer for collecting data from
// the "characters" SAX event.
private CharArrayWriter contents = new CharArrayWriter();
public void startDocument() throws SAXException {
stores = new Hashtable();
}

Similar Messages

  • Ejb-jar.xml DTD validation error?

    I am attempting to deploy a JAR on App Server 8 PE. The application does not contain any EJBs but I understand that the ejb-jar.xml descriptor is still needed. I am running the app server on Windows XP.
    My issue is as follows:
    I understand that the root element for the ejb-jar.xml file (<ejb-jar>) is required. Since I have no EJBs, I should be able to leave this root element blank (as I have in previoius successful deployments to earlier versions of Sun App Server). When I attempt to deploy, I receive the following DTD Validation error via the admin console:
    The content of element type "ejb-jar" is incomplete, it must match "(description?,display-name?,small-icon?,large-icon?,enterprise-beans,relationships?,assembly-descriptor?,ejb-client-jar?)".
    Am I missing something?
    My ejb-jar.xml file looks like:
    <!DOCTYPE ejb-jar PUBLIC
         "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
         "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
    <ejb-jar>
    </ejb-jar>
    Many thanks in advance to any assistance...

    I am attempting to deploy a JAR on App Server 8 PE.
    The application does not contain any EJBs but I
    I understand that the ejb-jar.xml descriptor is still
    needed. I am running the app server on Windows XP.
    My issue is as follows:
    I understand that the root element for the
    ejb-jar.xml file (<ejb-jar>) is required. Since I
    have no EJBs, I should be able to leave this root
    element blank (as I have in previoius successful
    deployments to earlier versions of Sun App Server).
    When I attempt to deploy, I receive the following
    g DTD Validation error via the admin console:
    The content of element type "ejb-jar" is incomplete,
    it must match
    "(description?,display-name?,small-icon?,large-icon?,e
    nterprise-beans,relationships?,assembly-descriptor?,ej
    b-client-jar?)".
    Am I missing something?
    My ejb-jar.xml file looks like:
    <!DOCTYPE ejb-jar PUBLIC
    "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans
    s 2.0//EN"
         "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
    <ejb-jar>
    </ejb-jar>
    Many thanks in advance to any assistance...I hav tried this and it is working
    <?xml version="1.0" encoding="UTF-8" ?>
    <ejb-jar
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
    version="2.1">

  • Weblogic 9.2 JDk 1.5 DTD Validation

    Hi
    We are using xerces parser and doing DTD Validation .
    We want to have all the DTD present in the local directory
    C:/temp( as reading from the WAR is a performance hit)
    When we try to run with Weblogic 8.1 ( with JDK1.4 and JDK1.5 ) the xml is being parsed properly and validated with DTD without any errors
    But when we are trying to Validate the DTD with Weblogic 9.2 and JDK 1.5 it gives the error
    C:/temp/a.dtd not found even though the DTD is present in that location .
    Is there a settiing in Weblogic 9.2 which needs to be set for it to read local file system files?
    Thanks
    Sachin

    weblogic 9.2 uses jdk 1.5_04 if i recall correctly.

  • DOM Parser Configuration...how to switch off DTD validation?

    Hi all,
    I am developing some implementation code in Java using JBuilder2005, in which DOM3 parser is also being utilised. Now the question is how to switch off DTD validation (seems its default mode is 'on') so that no validation will be carried out at all even DTD declaration statement is presented in an input XML document?
    Many thanks in advance
    Frank

    First of all, thank you so much for responding, DrClap. =)
    setValidating(false) of the DocumentBuilderFactory instance, factory, does not work as expected; it still stubbornly try to seek the external DTD file and fires 'IOException' error in case of no such a DTD.
    To follow up the EntityResolver approach, I searched online for almost the whole afternoon but still could not figure out how to do it exactly. In particular, I found http://www.jdom.org/docs/faq.html#a0350, which tells a way doing it, but I got 'StringBufferInputStream is deprecated' error. Then I changed to
    new InputStream(new ByteArrayInputStream("".getBytes()))adapted from http://forum.java.sun.com/thread.jspa?threadID=572919&messageID=2842185. But another error occurs: 'java.io.InputStream is abstract; cannot be instantiated'. Furthermore, I have looked at many docs(tutorials, APIs...) on parser configuration, usage of EntityResolver/setEntityResolver()...but they turned out not helpful. Could you please give out more details on how to do this using EntityResolver?? Many many thanks...

  • How to disable XML´s DTD validation in Weblogic10?

    Hello folks, we are trying to upgrade our server to Weblogic10, but it´s XML parser is validating XML´s DTD and ´cause we are behind a firewall we receive a error like:
    Tried all: ´6´ address, but could not connect over HTTP to server: 'www.w3.org', port: '80'
    Does anyone here known how to disable DTD validation in WL10?
    Regards,
    lottalava

    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.

  • Message Mapping - Turn Off dtd validation

    Hi,
    I would like to know how to turn off dtd validation in a message map.
    The source message type is based on dtd. When testing, I get the following error
    java.io.IOException: Failed to load resource from the context classloader of the current thread! Loading from classloader was caused by: java.io.FileNotFoundException: D:\usr\sap\XYZ\DVEBMGS01\j2ee\cluster\server0\abc.dtd (The system cannot find the file specified)
    I understand that the map requires the dtd to be present in the application folder. But, can I change some setting not to look up this file.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE MessageContainer SYSTEM "abc.dtd">

    Sorry Arvind. Not able to understand your question.
    The problem we are facing is, when the input xml file contains DocType declaration with reference to a dtd, we get an error stating the dtd is not found in the j2ee application folder.
    It works fine if the dtd is saved in the location. Also, it works fine if the DocType declaration is removed from the xml file. However, we are exploring an option where declaration is used but dtd is not available.
    Is there any way to achieve this?
    Thanks!

  • Disabling dtd validation

    I know it sounds odd.. but I need my appserver to run offline. basically I am creating a stand alone server and application installation that one of our marketing guys can take on the road on a laptop and demo to people where there is no internet.
    you know.. localhost style ;-)
    One problem.. when there is no internet, DTD validation for sun and oracle wesite DTDs all fail. Removing all dtd references or making them local would take as long as it would take me to write a script to do it... I am hoping there is just a setting in the application server that I can set to disable dtd validation. The whole app is done being developed.. I don't need my xml validated anymore! I need to be able to run without the intarwebnets!
    please help!

    Haven't worked with this but possibly this method of "deactivation" is not valid in 11gR2? Have you cross checked that with Oracle support?

  • Turn off DTD validation

    I am using the Xerces DOMParser that ships with WebLogic 6.0 (sp1). Does
    anyone know how to turn of DTD validation when parsing a file?
    Thanks in advance.

    in SAX it's the setFeature() method. I assume there's something similar for
    DOM because the Xerces DOM "parser" sits on top of SAX
    "Tony Hardee" <[email protected]> wrote in message
    news:[email protected]..
    I am using the Xerces DOMParser that ships with WebLogic 6.0 (sp1). Does
    anyone know how to turn of DTD validation when parsing a file?
    Thanks in advance.

  • DTD Validator

    Is there a DTD validator available for download? Also, is there
    a converted to BNF available?
    null

    I am not sure what you mean by "DTD Validator". If you mean
    chcking that a DTD is well-formed and has access to its entities
    then our XML Parser will do the job. As to conversion to BNF, we
    have nothing in this area until our XSL Processor becomes
    available.
    Oracle XML Team
    http://technet.oracle.com
    Oracle Technology Network
    Rob Jaeger (guest) wrote:
    : Is there a DTD validator available for download? Also, is
    there
    : a converted to BNF available?
    null

  • XML SAX dtd Validation Problem

    Hi,
              I’m having problems getting an xml document to validate within Weblogic 8.1. I am trying to parse a document that references both a dtd and xsd. Both the schema and dtd reference need to be substituted so they use local paths. I specify the schema the parser should use and have created an entityResolver to change the dtd reference.
              When this runs as a standalone app from eclipse the file parses and validates without a problem. When deployed to the app server the process seems to be unable read the contents of the dtd. Its not that it cannot find the file (no FileNotFoundException is thrown but this can be created if I delete the dtd) rather it seems to find no declared elements.
              Initial thought was that the code didn’t have access to read the dtd from its location on disk, to check I moved the dtd to within the deployed war and reference as a resource. The problem still persists.
              Code Snippet:
              boolean isValid = false;
              try {
              // Create and configure factory
              SAXParserFactory factory = SAXParserFactoryImpl.newInstance();
              factory.setValidating(true);
              factory.setNamespaceAware(true);
              // To be notified of validation errors in the XML document,
              // add a custom error handler to the document builder
              PIMSFeedFileValidationHandler handler
              = new PIMSFeedFileValidationHandler();
              // Create and Configure Parser
              SAXParser parser = factory.newSAXParser();
              parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
              parser.setProperty(NAMESPACE_PROPERTY_KEY, getSchemaFilePath());
              // Set reader with entityResolver for dtd
              XMLReader xmlReader = parser.getXMLReader();
              xmlReader.setEntityResolver(new SAXEntityResolver(this.dtdPath));
              // convert file to URL, as it is a remote file
              URL url = super.getFile().toURL();
              // Open an input stream and parse
              InputStream is = url.openStream();
              xmlReader.setErrorHandler(handler);
              xmlReader.parse(new InputSource(is));
              is.close();
              // get the result of parsing the document by checking the
              // errorhandler's isValid property
              isValid = handler.isValid();
              if (!isValid) {
              LOGGER.warn(handler.getMessage());
              LOGGER.debug("XML file is valid XML? " + isValid);
              } catch (ParserConfigurationException e) {
              LOGGER.error("Error parsing file", e);
              } catch (SAXException e) {
              LOGGER.error("Error parsing file", e);
              } catch (IOException e) {
              throw new FeedException(e);
              return isValid;
              See stack trace below for a little more info.
              2005-01-28 10:24:09,217 [DEBUG] [file] - Attempting validation of file 'cw501205.wa1.xml' with schema at 'C:/pims-feeds/hansard/schema/hansard-v1-9.xsd'
              2005-01-28 10:24:09,217 [DEBUG] [file] - Entity Resolver is using DTD path file:C:/Vignette/runtime_services/8.1/install/common/nodemanager/
              VgnVCMServer/stage/pims-hansard/pims-hansard.war/WEB-INF/classes/com/morse/pims/cms/feed/sax/ISO-Entities.dtd
              2005-01-28 10:24:09,227 [DEBUG] [file] - Creating InputSource at: file:C:/Vignette/runtime_services/8.1/install/common/nodemanager/VgnVCMServer/stage/pims-hansard/pims-hansard.war/WEB-INF/classes/com/morse/pims/cms/feed/sax/ISO-Entities.dtd
              2005-01-28 10:24:09,718 [WARN ] [file] - org.xml.sax.SAXParseException: Element type "Hansard" must be declared.
              org.xml.sax.SAXParseException: Element type "Session" must be declared.
              org.xml.sax.SAXParseException: Element type "DailyRecord" must be declared.
              org.xml.sax.SAXParseException: Element type "Volume" must be declared.
              org.xml.sax.SAXParseException: Element type "Written" must be declared.
              org.xml.sax.SAXParseException: Element type "WrittenHeading" must be declared.
              org.xml.sax.SAXParseException: Element type "Introduction" must be declared.
              … continues for all the elements in the doc
              2005-01-28 10:24:10,519 [DEBUG] [file] - XML file is valid XML? false
              2005-01-28 10:24:10,519 [WARN ] [file] - Daily Part file 'cw501205.wa1.xml' was not valid XML and was not processed.
              Has anybody seen this behavior before with weblogic and if so how have you resolved the issue.
              Thanks in Advance
              Adam

    It looks like you clicked on "Post" before you got around to explaining your problem. I don't see any error messages or any description of what was supposed to happen and what happened instead.
    Now, I don't know anything about XML Schema, but just guessing at how that unique name feature might be designed, and just guessing that your unique name is actually in the <userId> element, I would suggest that this:
    <xsd:unique name="un_name"> 
      <xsd:selector xpath="USER"/> 
      <xsd:field xpath="."/> 
    </xsd:unique> is at fault because it doesn't mention the <userId> element anywhere.

  • No DTD validation in SAX Parser

    I have a xml document which has a DocTYpe spec in it with a DTD reference, but the dtd file itself is not there. We tried to parsing it in Non validating mode , but it throws a fileNot Found Exception looking for the DTD file. we tried it on the SAXSample too, with same results.
    Is there any way around it.
    Thanks.
    Chirdeep

    We would like to be able to do this also.
    We use XML for messaging between systems and would like to be able to switch this off or on at run-time according to user preference. Validating against the DTD obviously requires extra processing time, we would like to check well-formedness en-route between systems to ensure that the message is complete, without doing a full check against the DTD. (This would then be done at the end-point of the journey).
    If no DTD is referenced then this works fine. However if a DTD is referenced in the XML and validation mode is set to off, it still wants to validate against a DTD.
    Is this a bug or is there are work-around ?

  • Ignoring a DTD validation at message mapping

    Hi,
    I'm facing the following situation: as a responce for a HTTP service consume, we are getting this payload:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE ChannelAdminResult SYSTEM "/AdapterFramework/channelAdmin/ChannelAdmin.dtd">
    <More tags....>
    the problem is that the message mapping is not able to get the dtd that validates the payload. I did try uploading the dtd file as external definition, but it still not working.
    Is there anyway to bypass the !DOCTYPE validation?
    Thanks in advance,
    Ariel

    Hello, I have the same problem. If you have an solution for it, please post it here anyway.
    In my case, the external reference is an http-adress. The server has an connection to it, but it doesn't work until now.
    I tested the way over the external  definition, too, but with the same effect.

  • Java DTD validation

    I am trying to validate an XML using a DTD which is already created, In the code below i would like to validate the XML. I have looked at a number of websites etc but i cannot work out how to put in the validation can someone please help. I am pulling my hair out.
    public class validation {
    BufferedReader in;
    StreamResult out;
    Document xmldoc;
    Element root;
    String xmlString;
    public static void main (String args[]) {
    new validation().doit();
    public void doit () {
    try{
         StringBuffer sBuffer = new StringBuffer();
         String str;
    in = new BufferedReader(new FileReader("clinicSchedule.xml"));
    out = new StreamResult("data.xml");
    while ((str = in.readLine()) != null) {
              System.out.println(str);
    sBuffer.append(str);
         in.close();
    initXML(sBuffer.toString());
    transformXML();
    catch (Exception e) { e.printStackTrace(); }
    public void initXML(String sFinalXML) throws ParserConfigurationException{
    // JAXP + DOM
    try
              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              DocumentBuilder builder = factory.newDocumentBuilder();
              factory.setIgnoringComments(true); // We want to ignore comments
              factory.setNamespaceAware(true);
              factory.setValidating(true);
              // Now use the factory to create a DOM parser
              DocumentBuilder parser = factory.newDocumentBuilder();
              System.out.println(sFinalXML);
              xmldoc = parser.parse(new InputSource(new StringReader(sFinalXML)));
         }catch ( SAXParseException spe ) {
              System.err.println( "Parse error: " +
              spe.getMessage() );
              System.exit( 1 );
         catch (Exception ex) {
              ex.printStackTrace();
         public void transformXML()
              try{
                   //Define source and destination Streams
                   DOMSource domSource = new DOMSource(xmldoc);
                   StreamResult myDestination=new StreamResult("output.html");
                   StringWriter stringWriter=new StringWriter();
                   //StreamResult myDestination=new StreamResult(stringWriter);
                   //Define XSL source stream
                   StreamSource myXSLSource=new StreamSource("emailStyle.xsl");
                   //Create Transformer from Factory
                   TransformerFactory myFactory =TransformerFactory.newInstance();
                   //Transfooooooorm!!!
                   Transformer myTransformer = myFactory.newTransformer(myXSLSource);
                   myTransformer.transform(domSource, myDestination);
                   //xmlString=stringWriter.toString();
              }catch(Exception e){
                   e.printStackTrace();
    }

    There's a number of posts on this topic, so I'm not going to repeat it here. Please, check the following entries in this forum:
    http://forum.java.sun.com/thread.jsp?forum=34&thread=158734
    http://forum.java.sun.com/thread.jsp?forum=34&thread=159320
    http://forum.java.sun.com/thread.jsp?forum=34&thread=172123
    http://forum.java.sun.com/thread.jsp?forum=34&thread=153776
    Good luck and - please - go easy on your hair.

  • Ignoring whitespaces without DTD validation

    Hi!
    I've been having some problems parsing an XML file with DOM, because I get text Nodes for each "new line" symbol in the file, and I want these to be ignored, so I tried to put the "setIgnoringElementContentWhitespace" of the DocumentBuilderFactory to true.
    The problem is that this property requires the parser to be in validating mode, and I don't have the DTD of the xml file... so I'd like it to be non validating.
    Can it be done?

    Ok, then... a DTD is needed to make the parser know when the whitespaces are ignorable, isn't it?
    I wrote a simple DTD and by-passed the problem. It works know.
    Thx for reading

  • DTD validation without a !DOCTYPE

    I am doing some integration with a third-party. The project involves sending an XML request, receiving a response, parsing, and displaying the results in a browser. I have received DTDs from the third party, and must validate the request before the message is sent (posted) from my side. However, the third party requires that a <!DOCTYPE> declaration should not exist in the document. Can someone give me an example of how to validate an XML document with no <!DOCTYPE>? I am building the document object with JDOM. Also, any suggestions on a parser implementation?
    Thanks,
    Ben

    This is the model I am using: I have millions of docs I need to
    validate, so I am reading one at a time in memory, I process
    the string for some offline edit operatiosn then validate the
    resulted xml string. I am creating the parser once in memory
    and validating each document by changing the xml string its
    supposed to parse. (all are being validated against same DTD)
    Now as I said before the timing actually surprised me also.. and I
    have no explenation either.. I am running on a Windows2000/jdk1.4
    and xerces.. and sax parser for validation. And the results were:
    With string manipulation to change doctype:
    DOMValidation: 13Microsecs
    SAXValidation: 10Microsecs
    and using entity stuff it was 29Microsecs. As I said I am just a
    messenger presenting the results, and I would like to find
    out also whats happening here.

Maybe you are looking for