SAXParser inside unsigned Applet: Validation with DTD

Hello!
I am trying to run an applet that performs some XML parsing ideally with DTD validation.
The issue is that I can't access files directly, but using tricks such as Class.getResourceAsStream() which I can do fine for my XML file my XML file. But then this xml has a reference to test.dtd (also in the jar file).
When the parser runs, it tries to open test.dtd "illegally" and a security exception is thrown. Any advice in how to avoid this?
BTW, I have already thought of:
* Traslating the DTD to a Schema
* Disabling validation
Would work, but not the solution I'm looking for :)

It doesn't seem like the SAXParser allows it, but if you use an XMLReader, you can specify an EntityResolver class.
The EntityResolver is called when SAX wants to open a resource. Your code can supply an InputSource to point to the resource you want.
Dave Patterson
Message was edited by:
d.patterson

Similar Messages

  • XML validation with DTD in java 1.5 not supporting

    Hi,
    I am facing a problem regarding validation of xml file with DTD tag in it.
    I have disabled the parser through setValidating(false) method.
    xml file is not parsed in JRE 1.5.but it is parsed in JRE 1.6.
    Why this is showing such a behavior?
    I have used xerces 2.9.0,xml-api.jar and other jar regarding XML api but still it is giving error.
    please help me.
    please provide a jar file name or its issue resolution in jre 1.5 or 1.4.

    thanks for your prompt reply.
    I required that it should be completely disabled in jre 1.5(jdk1.5 or 1.4).
    I am using DOM Parsing.I have currently disabled with follwowing method,
    builderFactory.setValidating(false);
    builderFactory.setFeature("http://xml.org/sax/features/validation",
         false);
         builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
         builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",false);
         builderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
         builderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
         factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    in 1.6 it is working fine but I required that i have to disabled it.but it is giving a error in jre1.5.
    Exception in thread "main" java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V
    I just want to disable the parsing in jdk version 1.5 or 1.4
    thanks in advance
    anand

  • XML validation with DTD

    Hi Team,
    I want to validate the XML content with DTD refered in the XML. I have problem now is my DTD are present in a jar file. How do I need to set systemid to the input source so that it works.
    <!DOCTYPE test SYSTEM "test.dtd">
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(true);
    factory.setNamespaceAware(true);
    inputSource.setSystemId("path");
    SAXParser parser = factory.newSAXParser();
    XMLReader reader = parser.getXMLReader();
    reader.setErrorHandler(new XmlValidationErrorHandler());
    reader.parse(inputSource);
    Regards
    Richard

    i believe the best way to handle that would be to set the EntityResolver on the XMLReader to your own implementation which loads the DTD from the jar.

  • Xerces2_6_2 validating with dtd and schema.. please help

    Hi I am having trouble validating an xml document using xerces2_6_2
    I have a DTD that containes only entity references, and a schema that is used to ensure the xml is valid.
    I get this error.
    Element type "my root tag" must be declared!
    It seems to expect all validation grammer to be in the dtd. I have sucessfully validated with xml spy and oxygen,(oxygen uses xerces too).
    This is a real pain I really would lie to take advantage of using schemas, I know I could just use entity references in this form and not have a dtd but this is really not acceptable.
    I have tried out all the xerces specific properties and features but this has not worked either.
    Perhaps I should implement a validator? Does anyone have any ideas?
    thanks

    My solution, I thought to take, wasn't the right way, but I have found following thread within the forum
    http://forum.java.sun.com/thread.jspa?forumID=34&threadID=527461
    The problem you have described points to a dtd error. Considering the thread above, it would make sense. It is a presumption, but perhaps that is because of the new Xerces version. I would try with an older one.
    Sorry, that I could help you along.

  • XML validation with DTD stored in String object

    Does anyone know if this is plausible......
    I am trying to validate some XML with a DTD... easy enough, right? The catch is that the dtd is NOT stored in a file somewhere and is also not declared in the XML to be validated. It is stored in a String object (as is the XML file to be validated).
    To clarify - I want to do something like this... but not sure how to incorporate the DTD.
    String dtd = // dtd definition here
    String xml = // xml text here (no URI at the top)
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser parser = factory.newSAXParser();
    DefaultHandler handler = new DefaultHandler();  // DTD handler??
    parser.parse(new InputSource(new StringReader(xml.toString())), handler);any help would be greatly appreciated.
    thanks in advance,
    Terrance

    I guess it makes the most sense to make the dtd local to the xml. Therefore I would only have one string with both the xml contents and dtd contents. That is how I am going to approach this unless I hear something different.

  • Validation with DTD: Bug in Oracle 10g?

    Hi
    The following example works with Oracle 11g, but not with Oracle 10g.
    I have a XML-document (familie.xml) and a DTD-Document (familie.dtd). The XML-document is not valide, because I changed the tag "Vater" into "Dad". Within
    the DTD the "Vater"-element is described as follow: <!ELEMENT Familie (Vater, Mutter, Kind) >. If I validate the document, I get in Oracle 11g this exception:
    Unexpected Error: ORA-31011: XML-Parsing not succesful
    LPX-00104: Warning: Element "Dad" is not declared in the DTD.
    Error at line 3 occured.
    This Error is right!! But if I try the SAME example in Oracle 10g, I don't get a Exception!!!! But I should become one.
    Have anyone tested DTD-Validation in Oracle 10g or is it a bug?
    <?xml version='1.0' encoding='ISO-8859-15' ?>
    <!-- Dokument beschreibt eine Familie -->
    <Familie>
         <Dad>
              <Name>Meier</Name>
    <Vorname>David</Vorname>
         </Dad>
         <Mutter>
              <Name>Baumann</Name>
              <Vorname>Charlotte</Vorname>
         </Mutter>
         <Kind>
              <Name>Slota</Name>
              <Vorname>Kaharina</Vorname>
         </Kind>
    </Familie>
    <!ELEMENT Familie (Vater, Mutter, Kind) >
    <!ELEMENT Vater (Name, Vorname)>
    <!ELEMENT Mutter (Name, Vorname)>
    <!ELEMENT Kind (Name, Vorname) >
    <!ELEMENT Name (#PCDATA) >
    <!ELEMENT Vorname (#PCDATA) >
    set directory TEST_DIR as '....';
    DECLARE
    v_parser xmlparser.parser;
    v_document xmldom.DOMDocument;
    v_nodeList xmldom.DOMNodeList;
    v_number NUMBER;
    v_xmlDatei VARCHAR2(32);
    v_dtdDatei varchar2(32);
    parserError EXCEPTION;
    PRAGMA EXCEPTION_INIT(parserError, -20100);
    BEGIN
    v_xmlDatei := 'familie.xml';
    v_dtdDatei := 'familie.dtd';
    v_parser := xmlparser.newParser();
    DBMS_XMLPARSER.setBaseDir(v_parser, 'TEST_DIR');
    xmlparser.setValidationMode(v_parser, TRUE);
    xmlparser.parseDTD(v_parser, v_dtdDatei, 'Familie');
    xmlparser.parse(v_parser, v_xmlDatei);
    v_document:=xmlparser.getDocument(v_parser);
    xmlparser.freeParser(v_parser);
    xmldom.freeDocument(v_document);
    EXCEPTION
    WHEN parserError THEN
    xmlparser.freeParser(v_parser);
    dbms_output.put_line('Fehler beim Parsen: ' || SQLERRM);
    WHEN OTHERS THEN
    dbms_output.put_line('Unerwarteter Fehler: ' || ' ' || SQLERRM);
    END;
    null
    Message was edited by:
    user638576

    Do your sequence and column have the same name? In your code sample, it looks like they do:
    INSERT INTO LSTKPI (KPIIDD, PRMNME, KPISUP, TEMIDD1)
    VALUES (KPIIDD.NEXTVAL, NEXTPRM.PRMNME, NEXTSTA.STANAM, PDRTEM_PKG_1.rids(i));
    Maybe that has confused the parser.
    As Oracle moves forward, you can expect more object-oriented functionality. That could mean that columns could have their own attributes or methods. If so, how is the parser to know whether in this code the value KPIIDD.NEXTVAL refers to the (external) sequence or a column attribute?
    As a suggestion, try renaming the sequence.
    create sequence KPIIDD_SEQ start with ... ;
    INSERT INTO LSTKPI (KPIIDD, PRMNME, KPISUP, TEMIDD1)
    VALUES (KPIIDD_SEQ.NEXTVAL, NEXTPRM.PRMNME, NEXTSTA.STANAM, PDRTEM_PKG_1.rids(i));
    HTH,
    - Doug

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

    If you are using Solaris , it has xml validation tool "xmllint", using this you can validate your xml against DTD.
    try with "xmllint --help " to see all the option.
    Message was edited by:
    sasrivas

  • DOM Validation with DTD

    Hi,
    can i validate an XMLDocument using a DTD ?
    I have the DOM and not the XML file;
    I would like to have a function that need a DTD URL...
    Thanks
    Andrea

    You can check the parser.setDocType() and parser.getDocType() and parser.parseDTD()

  • I have a trouble with the clipboard inside an applet

    I have created simple text editor as applet (by JTextPane). I have a trouble with the clipboard. The clipboard works correctly inside the applet, but I'm not able to paste text from outside text editors (e.g. notepad). But I found out that clipboard works correctly inside appletviewer.
    You can visit the applet on: http://www.newlink.be/abst/
    Please help
    P.S.: I'm sorry for my bad english

    This is because applets do not have access to the system clipboard by default. The only way to get around this is to make a signed applet.

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

  • File Access with unsigned Applet through editing the java.policy file

    I'am starting to lose my hair on this...
    I am trying to get an applet to run so that it can access the file system to move files on my local maschin. Because this applet is only running on my VM i can change the java.policy to avoid the signing of the applet.
    first of all, if i wrote in the java.policy file
    grant {
      permission java.security.AllPermission; 
    };everything is working perfekt.
    But I have not the intention to open the gates for any applet out there, so i want to limit the access to my applet. With every of the following versions I get at best an
    java.security.AccessControlException: access denied (java.io.FilePermission...
    My Setup
    My Java Version: jre1.6.0_02
    My applet is located unter the url
    http://admin.mydomain.com/applet.jar
    In Html i tryed the following different versions of loading the applet - none worked
    <applet codebase="http://admin.mydomain.com/" name="shortcut" code="start.class" archive="applet.jar" width="0" height="0"></applet>
    <applet codebase="http://admin.mydomain.com" name="shortcut" code="start.class" archive="applet.jar" width="0" height="0"></applet>
    <applet name="shortcut" code="start.class" archive="http://admin.mydomain.com/applet.jar" width="0" height="0"></applet>in java.policy i tryed following versions with every html applet load version
    grant codeBase "http://admin.x-press.de/-" {
      permission java.security.AllPermission; 
    grant codeBase "http://admin.x-press.de/+" {
      permission java.security.AllPermission; 
    grant codeBase "http://admin.x-press.de/applet.jar" {
      permission java.security.AllPermission; 
    };why is it with
    grant {
      permission java.security.AllPermission; 
    };working, and not with the other versions?
    i am almost bold now, please try to save my last hair from falling down.
    any suggestion would be nice
    thanks, feyyaz
    Message was edited by:
    feyyazdogu

    I read the mentioned documentation and your right, some of my versions were wrong, but after reading the doumentation again i came to following result which should had worked but didn't.
    java.policy
    grant codeBase "http://admin.mydomain.com/*" {
      permission java.security.AllPermission;
    HTML File
    <applet codebase="http://admin.mydomain.com/" name="shortcut" code="start.class" archive="applet.jar" height="0" width="0"></applet>if I am entering http://admin.mydomain.com/applet.jar i can download the jar, so the archive lays in the correct directory.
    what i am doing wrong? do i have to change an additional file somewhere else?

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

  • XML Validation with External XSD

    Hi
    I have a xml file having DTD declaration, but my requirment is to validate this xml file with External XSD not with DTD which is declared inside the file.
    on executing java code below it is looking for DTD. how to supress validating against dtd.
    SAXParserFactory factory = SAXParserFactory.newInstance();
                   factory.setValidating(false);
                   factory.setNamespaceAware(true);
                   SchemaFactory schemaFactory =
                       SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
                   factory.setSchema(schemaFactory.newSchema(
                       new Source[] {new StreamSource("C:\\vittal\\Project\\received\\development-1\\da_xsd\\daAuthoring.xsd")}));
                   SAXParser parser = factory.newSAXParser();
                   XMLReader reader = parser.getXMLReader();
                   reader.setErrorHandler(new LogErrorHandler());
                   reader.parse(new InputSource("C:\\vittal\\Project\\received\\A-ADD\\DAContentExamples_2\\SampleGuidance_1.xml"));error i am getting is License file saxon-license.lic not found. Running in non-schema-aware mode
    java.io.FileNotFoundException: C:\vittal\Project\received\A-ADD\DAContentExamples_2\daAuthoring.dtd (The system cannot find the file specified)

    Hi
    I have a xml file having DTD declaration, but my requirment is to validate this xml file with External XSD not with DTD which is declared inside the file.
    on executing java code below it is looking for DTD. how to supress validating against dtd.
    SAXParserFactory factory = SAXParserFactory.newInstance();
                   factory.setValidating(false);
                   factory.setNamespaceAware(true);
                   SchemaFactory schemaFactory =
                       SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
                   factory.setSchema(schemaFactory.newSchema(
                       new Source[] {new StreamSource("C:\\vittal\\Project\\received\\development-1\\da_xsd\\daAuthoring.xsd")}));
                   SAXParser parser = factory.newSAXParser();
                   XMLReader reader = parser.getXMLReader();
                   reader.setErrorHandler(new LogErrorHandler());
                   reader.parse(new InputSource("C:\\vittal\\Project\\received\\A-ADD\\DAContentExamples_2\\SampleGuidance_1.xml"));error i am getting is License file saxon-license.lic not found. Running in non-schema-aware mode
    java.io.FileNotFoundException: C:\vittal\Project\received\A-ADD\DAContentExamples_2\daAuthoring.dtd (The system cannot find the file specified)

  • Applet client with DataForms using dial-up

    Jdeveloper 3.2, IAS9i
    Hello,
    Somebody knows if the DataForms are efficient via dial-up?
    For example in the Online Orders sample,with an applet client (with DataForms, using dialup to connect to app. server). What happens when an user insert a new employee record. When an user navigate around the fields ocurrs a validation inside the Business Object Tier. What happens with the remote round trips?, It's faster?.
    Jdeveloper 3.2.2
    IAS9i
    Thanks a lot.
    null

    Any application designed to run over a dial -up connection must be extremely sensitive to the fact that dial-up connection is very slow due to it's bandwidth.
    Applets by default require downloading a lot of files to the browser. So you must download your app code, the jdbc drivers and any other required classses.
    Applets using BC4J components then must also download the BC4J code. BC4J uses a data cache, so data is also downloaded.
    Avoid using applets in this design.
    Use JavaServerPages(JSP's) (or servlets) which are a much "thinner" version of the "Thin client" group of tools(applets, servlets jsp's)
    WHY JSP's over servlets ??
    They are quicker to write than servlets

  • XML validation with JDOM / JAXP

    Hello,
    I am trying to validate xml file against schema file. I decided to use JDOM and JAXP.
    First question: is it a good choice?
    I did a first attempt but not sure I have understood all what I am doing :(
    First I have create a parser usinf org.jdom.*
    SAXBuilder parser = new SAXBuilderThen I built my document:
    Document doc = parser.build(myFile)These 2 steps are ok. But it does not do validation.
    I saw in the JDOM documentation that I can set a validation flag to true. I did it. First problem, I got the following error from JDOMException: Document is invalid: no grammar found.
    Is there a way to specify to the parser where to find the xsd file?
    As I did not find answer to this question by myself, I tried implementing the Schema class from JAXP:
    SAXBuilder parser = new SAXBuilder;
    Document doc = parser.build(myFile);
    Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaFile);
    ValidatorHandler vh = schema.newValidatorHandler();
    SAXOutputter so = new SAXOutputter(vh);
    so.output(doc);It does the validation against the schema file specified but I am not really sure about what I am doing here. The last 2 commands are not clear to me :(
    Then in my schema file, I have elements that have default value. I expected the following behavior: if the element is not in the xml file then the default will be used by the parser (and added in the tree). But it seems, it's not the case.
    Any help/explanation will be really appreciated.

    I am trying to validate xml file against schema file. I decided to use JDOM and JAXP.
    First question: is it a good choice?
    If only schema validation is required use the validation API in JDK 5.0.
    http://www-128.ibm.com/developerworks/xml/library/x-javaxmlvalidapi.html
    http://java.sun.com/developer/technicalArticles/xml/validationxpath/
    For validation with JDOM, the following validation application explains the procedure:import org.jdom.input.SAXBuilder;
    import org.xml.sax.SAXException;import org.jdom.*;
    import java.io.*;
    public class JDOMValidator{
    public void validateSchema(String SchemaUrl, String XmlDocumentUrl){
               try{
    SAXBuilder saxBuilder = new SAXBuilder("org.apache.xerces.parsers.SAXParser",true);<br/>saxBuilder.setValidation(true);
    saxBuilder.setFeature("http://apache.org/xml/features/validation/schema",true);
    saxBuilder.setFeature("http://apache.org/xml/features/validation/schema-full-checking",true);
    saxBuilder.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",SchemaUrl);
    Validator handler=new Validator();
    saxBuilder.setErrorHandler(handler);
    saxBuilder.build(XmlDocumentUrl);
    if(handler.validationError==true)
    System.out.println("XML Document has Error:"+handler.validationError+""+
    handler.saxParseException.getMessage());      
    else           
          System.out.println("XML Document is valid");
              }catch(JDOMException jde){
                }catch(IOException ioe){
    private class Validator extends DefaultHandler{     
         public boolean  validationError = false; 
         public SAXParseException saxParseException=null;    
      public void error(SAXParseException exception) throws SAXException{        
         validationError =true;
         saxParseException=exception; 
      public void fatalError(SAXParseException exception) throws SAXException  {
    validationError = true;     
    saxParseException=exception;
      public void warning(SAXParseException exception) throws SAXException       {
    public static void main(String[] argv)   {
       String SchemaUrl=argv[0];StringXmlDocumentUrl=argv[1];
       JDOMValidator validator=new JDOMValidator();
       validator.validateSchema(SchemaUrl,XmlDocumentUrl);
    }

Maybe you are looking for

  • MissingResourceException Error when Starting Application

    I am getting the following error when starting an Enterprise application in weblogic 10.3.6: .MissingResourceException: Can't find bundle for base name resources.Messages, locale en A snippet from my faces-config.xml file:      <application>      <lo

  • How to use JAXB generated classes with SOAP

    hello, I have a library of JAXB generated classes for my web service. There is a Java class for each web method defined in my schema. For example, my getLocation method is mapped to GetLocation.class. However my web service is SOAP based, so I am hav

  • Temp folder stopping me from replying to messages

    I am unable to reply to emails. I have version 24.6.0. When I click Send, error message says "Unable to open the temporary file C:\Users\Robert\AppData\Local\Temp\nsemail.eml. Check your 'Temporary Directory' setting." I tried to delete this and two

  • How to implement a Magnifier function

    Could someone tell me how to implement a magnifer effect in a Java application not Java Applet. Some example will be fine. Thanks

  • Microsoft visual c++ runtime library erorr

    this application has requested the runtime to terminate it in an unusual way. please contact the application's support team for more information please help me !