Make DocumentBuilder.parse ignore DTD references

Thanks to everyone in advance -
So this issue looks to be pretty popular, I have found a few solutions, but nothing seems to stop the downloading of dtd files, for instance ones sitting up on w3.org.
Here are some of the solutions i have found:
http://stackoverflow.com/questions/155101/make-documentbuilder-parse-ignore-dtd-references
http://forums.sun.com/thread.jspa?threadID=284209&forumID=34
When I use this solution:
myDocumentBuilder.setEntityResolver(new EntityResolver() {
          public InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
                 throws SAXException, java.io.IOException
            if (publicId.equals("--myDTDpublicID--"))
              // this deactivates the open office DTD
              return new InputSource(new ByteArrayInputStream("<?xml version='1.0' encoding='UTF-8'?>".getBytes()));
            else return null;
});it still continues to download the dtd.
Any suggestions?
Thanks,
Sam

                    MyDocumentBuilder.setEntityResolver(
                         new EntityResolver() {
                              public InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws SAXException, java.io.IOException {
                                   if(true){
                                        throw new IOException(publicId +"|"+ systemId);
                                   return null ;
                    );Good eye - It looks like that IOException is never being called - any suggestions?
Thanks,
Sam

Similar Messages

  • Ignore DTD reference in message monitoring (SXMB_MONI)

    Hi All,
    My Inbound Message (to be delivered to the target system) needs to have DTD reference as the target system mandates it.
    In the mapping I have added the DTD Reference (<!DOCTYPE .../>).
    Although the target system is happy ,massage monitoring is complaining that the DTD is missing when I want to display the XML message.This is a support issue as the inbound XML message is not diaplayed  in SXMB_MONI.
    Is there any way to work around it - Configuration or putting the DTDs somewhere in XI server.
    Thanks in Advance,
    Bikram

    Rather than add the DTD reference in a message mapping, you could try add it in a Java module attached to the receiver/outbound module-chain of your target communication channel.  This way the DTD line would not get added until after the message has left the integration server.
    Check out the following guide:
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/02706f11-0d01-0010-e5ae-ac25e74c4c81
    Let me know how you get on.
    (+ please assign me some forum points if you found this useful).
    Thanks,
    Paul Digance.

  • Regarding DocumentBuilder.parse method returns reference as null value.

    Hi
    We are in the process of migrating code which works on WebSphere/JBOSS to WLS..
    We are using DocumentBuilder object for parsing the Locale related xml data. I understand that the DocumentBuilder is provided by DocumentBuilderFactory which is an interface whose implementation is server specific.
    But when the Document Builder parse method is called with a valid file path, we are getting System.Out of doc.getFirstChild().getLocalName() as null (which ideally should have been the name of the first node). No Errors are observed .
    For WLS, the parser is giving the document object reference as null whereas in other servers like Websphere and JBOSS we are able to parse the same xml with proper object reference.
    Could you please help in this regard?
    Thanks and regards
    Anil

    Hi Vmotamar,
    If you think that the parsers available as part of WebLogic are causing the issues, Then you can use your Own Parsers while migrating to WebLogic Server. I mean Get the Parser Jar files which u used as part of JBoss or WebSphere and put it inside the "APP-INF\lib" directory of your EAR Application or Put them inside "WEB-INF\lib" of your WEBApplication...and then Apply ClassLoader Filtering feature provided by WebLogic ...which allows an application to use It's Own Jars\Classes ...
    Please refer to: http://forums.oracle.com/forums/thread.jspa?threadID=1109267&tstart=150 and in http://weblogic-wonders.com/weblogic/parsers_issues
    Thanks
    Jay SenSharma
    http://weblogic-wonders.com/weblogic/parsers_issues/ (WebLogic Wonders Are Here)

  • Ignoring a DTD reference

    I'm trying to load an existing XML document that specifies the DTD as a relative reference:
    <!DOCTYPE Overlay SYSTEM "overlay.dtd" >
    When I have the DTD in the same directory as the XML file things work, when it's not there it fails with a file not found exception as expected:
    java.io.FileNotFoundException: C:\...\overlay.dtd (The system cannot find the file specified)
    However it still fails with that even when validation is disabled.
    Is there any way to have the parser completely ignore the DTD reference?

    I'd suggest you shouldn't be putting those DTD references in your XML if they aren't going to be used. However perhaps you could write your own EntityResolver that catches references to that DTD and replaces them with a reference to some other DTD... maybe a trivial one that does no validation.

  • Dom can't parse dtd reference in xml file

    Hi all,
    I am trying to parse a xml file (hibernate mapping file *.hbm.xml) using DOM. But itis getting timeout errorwhile parsing due to the external dtd reference in the xml file.
    <!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >I understand that the program is trying to access the document and is not being able to do so. But I don't have any clue to solve this problem. I don't want to remove the reference from the xml file.
    The following method is trying to parse the xml file:
    public void parseXML(String file) {
            factory = DocumentBuilderFactory.newInstance();
            System.out.println(file);
             try {
                 builder = factory.newDocumentBuilder();
                 document = builder.parse(file);
                 Element docEle = document.getDocumentElement();
                 NodeList n1 = docEle.getElementsByTagName("class");
                for(int i = 0; i < n1.getLength(); i++) {
                       Element e1 = (Element) n1.item(i);
                       String nm = e1.getAttribute("name");
                     System.out.println(nm);
            } catch(Exception e) {
                throw new RuntimeException(e);
        }Please help me on this....I am at no end....Please let me know if there is any method so that the parser will overlook this reference and will parse the xml file....or any other sort of solution....
    Thanks in advance...
    Anir

    Can you provide a working sample?  Upload to Onedrive and share it with us.
    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.
    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined
    objects and unknown namespaces.

  • Java.lang.NullPointerException javax.xml.parsers.DocumentBuilder.parse

    Hi all,
    i have a problem by solving an error in my code. The Code is mainly from Ian Darwin.
    The code i am running works with j2sdk1.4.2_04. But now i have to bring it to work with jdk1.6.0_13.
    The code parses xml documents. With small xml documents the code works. With large xml documents i get the following error while running the produced class file.
    Exception in thread "main" java.lang.NullPointerException
    at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.setChunkIndex(DeferredDocumentImpl.java:1944)
    at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.appendChild(DeferredDocumentImpl.java:644)
    at com.sun.org.apache.xerces.internal.parsers.AbstractDOMParser.characters(AbstractDOMParser.java:1191)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.characters(XMLDTDValidator.java:862)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:463)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:208)
    at XParse.parse(XParse.java:38)
    at XParse$JFileChooserrv.<init>(XParse.java:119)
    at XParse.main(XParse.java:213)
    I know what a java.lang.NullPointerException mens. But i don't know where i have to look for. Specially i don't know what or where "com.sun.org.apache...." is.
    Is there a package that a have to add to the environment? Can some one tell my where i can find this package?
    I wrote the code for some years ago, 2006 or so. With the knew jdk1.6.0_13 some thinks chance in the environment. Couldn't find what exactly.
    The code has only 215 lines, but some how i can't add it to this Message, because Maximum allowed is only 7500.
    Is there an other Forum, which may is better for my question?

    Here is the code:
    import java.io.*;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.Container;
    import javax.swing.JTextArea;
    * This code is mainly from @author Ian Darwin, [email protected]
    public class XParse {
         /** Convert the file */
         public static void parse(File file, boolean validate) {
              try {
                   System.err.println("");
                   String fileName = file.getAbsolutePath();
                   System.err.println("Parsing " + fileName + "...");
                   // Make the document a URL so relative DTD works.
                   //String uri = new File(fileName).getAbsolutePath();
                   //System.err.println(uri);
                   DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
                   if (validate)
                   f.setValidating(true);
                   DocumentBuilder p = f.newDocumentBuilder();
                   p.setErrorHandler(new MyErrorHandler(System.err));
                   //XmlDocument doc = XmlDocument.createXMLDocument(file);
                   boolean vaild =  p.isValidating();
                   if (vaild) {
                        System.out.println("yes parsing");
                        Document doc = p.parse(file); // <<<< ERROR
                   System.out.println("Parsed OK");
              } catch (SAXParseException ex) {
                   System.err.println("+================================+");
                   System.err.println("|       *SAX Parse Error*        |");
                   System.err.println("+================================+");
                   System.err.println(ex.toString());
                   System.err.println("At line " + ex.getLineNumber());
                   System.err.println("+================================+");
              } /**catch (RuntimeException ex) {
                   System.err.println("+================================+");
                   System.err.println("|       *SAX Parse Error*        |");
                   System.err.println("+================================+");
                   System.err.println(ex.toString());
                   //System.err.println("At line " + ex.getLineNumber());
                   //System.err.println("At line " + ex.getMessage());
                   System.err.println("+================================+");
              }**/ catch (SAXException ex) {
                   System.err.println("+================================+");
                   System.err.println("|          *SAX Error*           |");
                   System.err.println("+================================+");
                   System.err.println(ex.toString());
                   System.err.println("+================================+");
              /*}} catch (SAXNotRecognizedException  ex) {
                   System.err.println(" no SAX");*/
              } catch (ParserConfigurationException ex) {
                   System.err.println(" ???");
               } catch (IOException ex) {
                   System.err.println("+================================+");
                   System.err.println("|           *XML Error*          |");
                   System.err.println("+================================+");
                   System.err.println(ex.toString());
    private static class JFileChooserrv {
         JFileChooserrv(JFrame f, boolean vverabreiten) {
              String openfile;
              String verror;
              boolean validate = true;
              final JFrame frame = f;
              String vFilename = "Z:\\Boorberg\\parsen_vista\\daten";
              //String vFilename = "C:\\";
              File vFile = new File(vFilename);
              final JFileChooser chooser = new JFileChooser(vFile);
              JFileFilter filter = new JFileFilter();
              filter.addType("xml");
              filter.addType("sgml");
              filter.addType("html");
              filter.addType("java");
              filter.setDescription("strukturfiles");
              chooser.addChoosableFileFilter(filter);
              boolean vjeas = true;
              chooser.setMultiSelectionEnabled(vjeas);
              int returnVal = chooser.showOpenDialog(frame);
              if (returnVal == JFileChooser.APPROVE_OPTION) {
                   //Array  filearry[] = chooser.getSelectedFiles();
                   //if (vFile = chooser.getSelectedFiles()) {
                   //File  file[] = chooser.getSelectedFiles();
                   File  vfile[] = chooser.getSelectedFiles();
                   //String openfile = new String();
                   int vlenght = vfile.length;
                   if (vlenght>1) {
                        int x=0;
                        while (x< vlenght) {
                                  parse(vfile[x], validate);
                                  x = x +1;
                   if (vlenght<=1) {
                        File v2file = chooser.getSelectedFile();
                             parse(v2file, validate);
              } else {
                   System.out.println("You did not choose a filesystem           object.");
         System.exit(0);
    private static class JFileFilter extends javax.swing.filechooser.FileFilter {
         protected String description, vnew;
         protected ArrayList<String> exts = new ArrayList<String>();
         protected boolean vtrue;
         public void addType(String s) {
              exts.add(s);
         /** Return true if the given file is accepted by this filter. */
         public boolean accept(File f) {
              // Little trick: if you don't do this, only directory names
              // ending in one of the extentions appear in the window.
              if (f.isDirectory()) {
                   return true;
              } else if (f.isFile()) {
                   Iterator it = exts.iterator();
                   while (it.hasNext()) {
                        if (f.getName().endsWith((String)it.next()))
                             return true;
              // A file that didn't match, or a weirdo (e.g. UNIX device file?).
              return false;
         /** Set the printable description of this filter. */
         public void setDescription(String s) {
              description = s;
         /** Return the printable description of this filter. */
         public String getDescription() {
              return description;
    private static class MyErrorHandler implements ErrorHandler {
            // Error handler output goes here
            private PrintStream out;
            MyErrorHandler(PrintStream out) {
                this.out = out;
             * Returns a string describing parse exception details
            private String getParseExceptionInfo(SAXParseException spe) {
                String systemId = spe.getSystemId();
                if (systemId == null) {
                    systemId = "null";
                String info = "URI=" + systemId +
                    " Line=" + spe.getLineNumber() +
                    ": " + spe.getMessage();
                return info;
            // The following methods are standard SAX ErrorHandler methods.
            // See SAX documentation for more info.
            public void warning(SAXParseException spe) throws SAXException {
                   //System.exit(0);
                //out.println("Warning: " + getParseExceptionInfo(spe));
            public void error(SAXParseException spe) throws SAXException {
                   //System.exit(0);
                String message = "Error: " + getParseExceptionInfo(spe);
                throw new SAXException(message);
            public void fatalError(SAXParseException spe) throws SAXException {
                   //System.exit(0);
                String message = "Fatal Error: " + getParseExceptionInfo(spe);
                throw new SAXException(message);
         public static void main(String[] av) {
              JFrame vframe = new JFrame("chose files to pars");
              boolean vverabreiten = true;
              boolean validate = true;
              JFileChooserrv vdateienwaehlen = new JFileChooserrv(vframe, vverabreiten);
    }The Stack Trace i posted in the last Message. But i couldn't read it, i am not a programmer.

  • How to ignore .dtd

    please help me for this problem
    I have a xml file: datasources.xml
    <?xml version = '1.0' encoding = 'windows-1252'?>
    <!DOCTYPE data-sources PUBLIC "Orion data-sources" "http://xmlns.oracle.com/ias/dtds/data-sources.dtd">
    <data-sources>
    </data-sources>
    and I have this code to parse file xml
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    Document doc = docBuilder.parse (new File("datasources.xml"));
    it works ok if I internet connecting is ok. but if i can't connect to internet, i doesn't work, but throws an Exception:
    java.net.UnknownHostException: xmlns.oracle.com
    anybody know how to ignore dtd when parse file xml???
    please help me, thanks in advance,
    TuanTA

    Refer
    http://www.oracle.com/technology/sample_code/tutorials/parser/domdtd/setup.htm#IgnoreDtd

  • Adding DTD reference in xml

    hi,
          This way i am creating xml,
            var cAcrobat += "<Root>";
            cAcrobat += "<Sample>" + "Something" + "</Sample>";
            cAcrobat += "</Root>";
            this.createDataObject("Acrobat.xml", cAcrobat);
            var Acrobat = this.getDataObjectContents("Acrobat.xml");
            cAcrobat = util.stringFromStream(Acrobat,  "utf-8");
            var myXML = XMLData.parse(cAcrobat, false);
            var cAcrobat = myXML.saveXML('pretty');
            var Acrobat = util.streamFromString(cAcrobat, "utf-8");
            this.setDataObjectContents("Acrobat.xml", Acrobat);
    and as a result it is creating an xml file as an attachment to pdf,  as follows,
      <?xml version="1.0" encoding="UTF-8" ?>
    - <xfa:data xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
    - <Root>
      <Sample>Something</Sample>
      </Root>
      </xfa:data>
    but i want to add DTD reference to xml file before the Root node  and after adding it should create xml like this,
    <?xml version="1.0" encoding="UTF-8" ?>
    "<!DOCTYPE  Some-application SYSTEM 'file:C:/SomeFolder/Test.dtd'>";
    - <xfa:data xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
    - <Root>
      <Sample>Something</Sample>
      </Root>
      </xfa:data>
    please tell me how to add this dtd reference in xml file, and whater i am doing above is correct or not?
    please tell me how to add dtd reference in xml file.

    I already created xml file as an attachment to pdf as explained in my 1st post.  now my problem is
    How to add DTD syntax line into XML using acrobat java script or E4X objects(?). like the one below
    <DOCTYPE SomeApp:MyformData SYSTEM "C:/myreference.dtd">

  • Has anybody used DocumentBuilder.parse(URL)

    Hi friends
    Has anybody used DocumentBuilder.parse(URL) for make document object.
    I have the following piece of code
    <code>
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    System.out.println("| Start | Fetch xml"); // ------------ 1
    Document document = builder.parse("http://some url that gives back XML");
    System.out.println("| Stop | Fetch xml"); // ------------- 2
    </code>
    Now the problem is .. once in a while the code will hang at point 1 and will never reach point 2. Exception handling has been done.. but there are no exceptions being logged. The code simply hangs.
    Please let me know if you have also faced the same or similiar problem.
    Thanking in anticipation
    Partha.

    Is it similar with a file URL instead a http URL.
    Use
    Document document = builder.parse("file://c:/xmlFile");
    instead of
    Document document = builder.parse("http://some url that gives back XML");

  • XSDBuilder fails to resolve DTD references

    I am evaluating XDK 9.2.0.5.0 for Java and have encountered a problem
    with XML Schema support.
    I am using XSDBuilder to build an XMLSchema object from several .xsd
    files. The main .xsd file is secext.xsd, and this file imports other
    .xsd files. I assign an EntityResolver to the XSDBuilder so that all
    imported schema files will be read from my local file system, rather
    than being retrieved from the Internet.
    XSDBuilder does call my EntityResolver to resolve the import
    statements in the XML Schema files; however, it fails to call my
    EntityResolver to resolve XMLSchema.dtd reference in the DOCTYPE
    declaration of xml.xsd.
    I am using Oracle XDK version 9.2.0.5.0 on Solaris 8 with Java 1.4. I
    have also tried version 10.1.0.0.0 beta and received the same results.
    Here is the test case:
    Download the following files and save them in /tmp/xsd/.
    http://schemas.xmlsoap.org/ws/2002/04/secext/secext.xsd
    http://www.w3.org/2001/xml.xsd
    http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd
    http://www.w3.org/2001/XMLSchema.dtd
    Compile and run OracleSchemaTest.java, passing 'secext.xsd' as the
    command line arg.
    java dfranklin.OracleSchemaTest secext.xsd
    It produces the following output:
    resolveEntity: null, secext.xsd
    resolved to /tmp/xsd/secext.xsd
    resolveEntity: http://schemas.xmlsoap.org/ws/2002/04/secext, http://www.w3.org/2001/xml.xsd
    resolved to /tmp/xsd/xml.xsd
    <Line 2, Column 80>: XML-0112: (Fatal Error) Error opening external DTD 'XMLSchema.dtd'.
    Exception in thread "main" oracle.xml.parser.schema.XSDException: Error opening external DTD 'XMLSchema.dtd'.
    at oracle.xml.parser.schema.XSDBuilder.parseIncludeAndImport(XSDBuilder.java:814)
    at oracle.xml.parser.schema.XSDBuilder.parseTopLevelElem(XSDBuilder.java:662)
    at oracle.xml.parser.schema.XSDBuilder.buildSchema(XSDBuilder.java:486)
    at oracle.xml.parser.schema.XSDBuilder.build(XSDBuilder.java:304)
    at oracle.xml.parser.schema.XSDBuilder.build(XSDBuilder.java:249)
    at dfranklin.OracleSchemaTest.buildXMLSchema(OracleSchemaTest.java:48)
    at dfranklin.OracleSchemaTest.run(OracleSchemaTest.java:29)
    at dfranklin.OracleSchemaTest.main(OracleSchemaTest.java:23)
    The output shows that the EntityResolver is not being called to
    resolve 'XMLSchema.dtd'.
    === begin OracleSchemaTest.java ===
    package dfranklin;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStream;
    import oracle.xml.parser.schema.XMLSchema;
    import oracle.xml.parser.schema.XSDBuilder;
    import oracle.xml.parser.schema.XSDException;
    import oracle.xml.parser.v2.XMLError;
    import org.xml.sax.InputSource;
    public class OracleSchemaTest
    implements org.xml.sax.EntityResolver
    private static String xsdstr;
    private static String basepath = "/tmp/xsd";
    public static void main(String[] args)
    throws Exception
    xsdstr = args[0];
    new OracleSchemaTest().run();
    public void run()
    throws Exception
    XMLSchema xmlSchema = buildXMLSchema(xsdstr);
    System.out.println("xmlSchema=" + xmlSchema);
    public XMLSchema buildXMLSchema(String systemId)
    throws Exception
    XSDBuilder xsdBuilder = new XSDBuilder();
    xsdBuilder.setEntityResolver(this);
    InputStream xsdin = null;
    InputSource insrc = resolveEntity(null, xsdstr);
    if (insrc != null) {
    xsdin = insrc.getByteStream();
    if (xsdin == null) {
    throw new IOException("Can't resolve entity " + xsdstr);
    XMLSchema xmlSchema = (XMLSchema)xsdBuilder.build(xsdin, null);
    return xmlSchema;
    public InputSource resolveEntity(String publicId, String systemId)
    throws
    org.xml.sax.SAXException,
    java.io.IOException
    System.err.println("resolveEntity: " + publicId + ", " + systemId);
    String fn;
    if ("http://www.w3.org/2001/xml.xsd".equals(systemId)) {
    fn = basepath + "/" + "xml.xsd";
    } else if ("http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd".equals(systemId)) {
    fn = basepath + "/" + "xmldsig-core-schema.xsd";
    } else if ("http://www.w3.org/2001/XMLSchema.dtd".equals(systemId)) {
    fn = basepath + "/" + "XMLSchema.dtd";
    } else {
    fn = basepath + "/" + systemId;
    try {
    InputStream in = new FileInputStream(fn);
    System.err.println("resolved to " + fn);
    InputSource insrc = new InputSource(in);
    insrc.setSystemId(systemId);
    return insrc;
    } catch (FileNotFoundException e) {
    return null;
    ==== end OracleSchemaTest.java ===

    I am evaluating XDK 9.2.0.5.0 for Java and have encountered a problem
    with XML Schema support.
    I am using XSDBuilder to build an XMLSchema object from several .xsd
    files. The main .xsd file is secext.xsd, and this file imports other
    .xsd files. I assign an EntityResolver to the XSDBuilder so that all
    imported schema files will be read from my local file system, rather
    than being retrieved from the Internet.
    XSDBuilder does call my EntityResolver to resolve the import
    statements in the XML Schema files; however, it fails to call my
    EntityResolver to resolve XMLSchema.dtd reference in the DOCTYPE
    declaration of xml.xsd.
    I am using Oracle XDK version 9.2.0.5.0 on Solaris 8 with Java 1.4. I
    have also tried version 10.1.0.0.0 beta and received the same results.
    Here is the test case:
    Download the following files and save them in /tmp/xsd/.
    http://schemas.xmlsoap.org/ws/2002/04/secext/secext.xsd
    http://www.w3.org/2001/xml.xsd
    http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd
    http://www.w3.org/2001/XMLSchema.dtd
    Compile and run OracleSchemaTest.java, passing 'secext.xsd' as the
    command line arg.
    java dfranklin.OracleSchemaTest secext.xsd
    It produces the following output:
    resolveEntity: null, secext.xsd
    resolved to /tmp/xsd/secext.xsd
    resolveEntity: http://schemas.xmlsoap.org/ws/2002/04/secext, http://www.w3.org/2001/xml.xsd
    resolved to /tmp/xsd/xml.xsd
    <Line 2, Column 80>: XML-0112: (Fatal Error) Error opening external DTD 'XMLSchema.dtd'.
    Exception in thread "main" oracle.xml.parser.schema.XSDException: Error opening external DTD 'XMLSchema.dtd'.
    at oracle.xml.parser.schema.XSDBuilder.parseIncludeAndImport(XSDBuilder.java:814)
    at oracle.xml.parser.schema.XSDBuilder.parseTopLevelElem(XSDBuilder.java:662)
    at oracle.xml.parser.schema.XSDBuilder.buildSchema(XSDBuilder.java:486)
    at oracle.xml.parser.schema.XSDBuilder.build(XSDBuilder.java:304)
    at oracle.xml.parser.schema.XSDBuilder.build(XSDBuilder.java:249)
    at dfranklin.OracleSchemaTest.buildXMLSchema(OracleSchemaTest.java:48)
    at dfranklin.OracleSchemaTest.run(OracleSchemaTest.java:29)
    at dfranklin.OracleSchemaTest.main(OracleSchemaTest.java:23)
    The output shows that the EntityResolver is not being called to
    resolve 'XMLSchema.dtd'.
    === begin OracleSchemaTest.java ===
    package dfranklin;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStream;
    import oracle.xml.parser.schema.XMLSchema;
    import oracle.xml.parser.schema.XSDBuilder;
    import oracle.xml.parser.schema.XSDException;
    import oracle.xml.parser.v2.XMLError;
    import org.xml.sax.InputSource;
    public class OracleSchemaTest
    implements org.xml.sax.EntityResolver
    private static String xsdstr;
    private static String basepath = "/tmp/xsd";
    public static void main(String[] args)
    throws Exception
    xsdstr = args[0];
    new OracleSchemaTest().run();
    public void run()
    throws Exception
    XMLSchema xmlSchema = buildXMLSchema(xsdstr);
    System.out.println("xmlSchema=" + xmlSchema);
    public XMLSchema buildXMLSchema(String systemId)
    throws Exception
    XSDBuilder xsdBuilder = new XSDBuilder();
    xsdBuilder.setEntityResolver(this);
    InputStream xsdin = null;
    InputSource insrc = resolveEntity(null, xsdstr);
    if (insrc != null) {
    xsdin = insrc.getByteStream();
    if (xsdin == null) {
    throw new IOException("Can't resolve entity " + xsdstr);
    XMLSchema xmlSchema = (XMLSchema)xsdBuilder.build(xsdin, null);
    return xmlSchema;
    public InputSource resolveEntity(String publicId, String systemId)
    throws
    org.xml.sax.SAXException,
    java.io.IOException
    System.err.println("resolveEntity: " + publicId + ", " + systemId);
    String fn;
    if ("http://www.w3.org/2001/xml.xsd".equals(systemId)) {
    fn = basepath + "/" + "xml.xsd";
    } else if ("http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd".equals(systemId)) {
    fn = basepath + "/" + "xmldsig-core-schema.xsd";
    } else if ("http://www.w3.org/2001/XMLSchema.dtd".equals(systemId)) {
    fn = basepath + "/" + "XMLSchema.dtd";
    } else {
    fn = basepath + "/" + systemId;
    try {
    InputStream in = new FileInputStream(fn);
    System.err.println("resolved to " + fn);
    InputSource insrc = new InputSource(in);
    insrc.setSystemId(systemId);
    return insrc;
    } catch (FileNotFoundException e) {
    return null;
    ==== end OracleSchemaTest.java ===

  • DocumentBuilder parser, DOM doucment object from a XML file error

    Hi guys
    I created a program which parses a xml and creates a DOM document object from
    it. The parser is validating.
    class xmlParser
        //create arrylist to store employee in
        private ArrayList<Employee> employeeStore = new ArrayList<Employee>();
        private DocumentBuilder parser;
        private static Document document;     
        //create an instant of Employee to be added to the arraylist
        private Employee theEmployee = new Employee();
        //create an instant of Address to be added to Employee to again be
        //added to Employee
        private Address employeeAddress = new Address();
        public xmlParser()
        public xmlParser(String myfile) throws IOException 
              //validate the XML document agaisnt the given dtd
              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              factory.setValidating(true);
              factory.setIgnoringElementContentWhitespace(true);
              try {
                  parser = factory.newDocumentBuilder();
              }catch(javax.xml.parsers.ParserConfigurationException d) {
                   System.out.println("error with new document builder");
              //create document object (DOM tree) from xml file
              try {
                  document = parser.parse(new File(myfile));
              }catch(org.xml.sax.SAXException e) {
                  System.out.println("Error with parser file still creating xml personnel2");
        } In my main method when i call:
    xmlParser parsertree = new xmlParser("personnel.xml"); the exception keeps getting thrown and i get my my message back "Error with parser file still creating xml personnel2"
    Can't seem to figure it out, any ideas would be great.
    Thanks alot

    Hi,
    A - Check that the xml file is located in the same directory where you
    run your app.
    B - Check that the xml file is correct (in XML way).
    Suggestion : you may print the exception message, it might help.
    Hope that help,
    Jack

  • Can't convert oracle.xml.parser.DTD to oracle.xml.parser.v2.DTD.

    I am getting the following Error while trying
    to compile the SampleMain.java file(Generating an XML document from a given Employee.dtd).
    I have set my classpath to use xmlparser.jar.
    D:\XMls>javac SampleMain.java
    SampleMain.java:65: Can't convert oracle.xml.parser.DTD to oracle.xml.parser.v2.DTD.
    main(java.l
    ang.String[]).
    generator.generate(dtd, doctype_name);

    Would you check the java parser version you are using? If using java parser V2, the normal lib name is xmlparserv2.jar.
    null

  • URGENT:  javax.xml.parsers.DocumentBuilder.parse() method issue

    Hi folks,
    I have an urgent parsing problem. I developed an app with JDK1.4 and now it needs to run on JDK1.3.1. The problem is this:
    If I use the DocumentBuilder.parse() method shipped with JDK1.4 it will parse a document containing namespaces WITHOUT a namespace declaration in the root element. However, since XML support doesn't ship with JDK1.3.1 I need to use JAXP. If I try this with the DocumentBuilder.parse() version shipped with JAXP (latest version) the parse method throws a NullPointerException. If I put the namespace declaration in the document it will parse fine. I tried setting the DocumentBuilderFactory.setNamespaceAware() explicitly to false (should be the default) but no luck. Any ideas other than adding the declaration (long story why I don't want it there...)
    thanks

    example, with declaration of namespace:
    <?xml version="1.0" encoding="UTF-8"?>
    <pre:root xmlns:inn="http://blablabla/inn/version/1.0/">
    <pre:metadata>
    <pre:dublin-core>
    <pre:title>mytitle</pre:title>
    <pre:description>mydesc</pre:description>
    <pre:creator>bjmann</pre:creator>
    </inn:dublin-core>
    </pre:root>
    example, without declaration:
    <?xml version="1.0" encoding="UTF-8"?>
    <pre:root>
    <pre:metadata>
    <pre:dublin-core>
    <pre:title>mytitle</pre:title>
    <pre:description>mydesc</pre:description>
    <pre:creator>bjmann</pre:creator>
    </inn:dublin-core>
    </pre:root>
    this may help...

  • DocumentBuilder.parse classpath problem

    Hi, I've the "xerces.jar" in my classpath, and
    I'm using it like this:
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.servlet.http.HttpServletRequest;
    import org.xml.sax.helpers.DefaultHandler;
    import org.xml.sax.SAXException;
    //... etc..
    Document mapDoc = null;
    Element mapRoot = null;
    try {
    DocumentBuilderFactory docbuilderfactory =
    DocumentBuilderFactory.newInstance();
    DocumentBuilder docbuilder = docbuilderfactory.newDocumentBuilder();
    mapDoc = docbuilder.parse("/usr/home/tomsicp/site.xml");
    //..... etc
    The file compiles just fine, but when I run it on a
    "SunOS 5.8 sun4u sparc, Ultra-60" I'm getting
    "java.lang.NoClassDefFoundError: org/xml/sax/InputSource
    at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
    at <linenumber in my file>
    When I run it on a "Linux 2.4.7-10smp #1"
    everything is just fine.
    I've got the exact same profile on both boxes, and the xerces.jar
    file is exactly the same.
    Any thoughts on why this is happening?
    thanks,
    Paul

    what JDK do you use on each machine?

  • How to ignore DTD in xml files under JAXB?

    hi,
    I have a program that has to access files which declare they use a DTD that no longer exists on the web in that location.
    we don't have the option to alter the xml files since they don't belong to us!
    I've written an equivalent schema and its all working with the files that have correct DTD references.
    Is there a way to tell the unmarshaller not to attempt to use the DTD that the documents declare?
    thanks,
    asjf

    I've found that by opening a inputstream to the XML file and wrapping it to filter the DTD out altogether and passing that inputstream to JAXB does the trick.
    this seems actually faster, since it doesn't go off on the net to look for the dtd!
    is this not catered for already somewhere??
    thanks,

Maybe you are looking for

  • Excel sheet download

    hi experts,    i need to shedule a report in back ground which has to download a excel sheet on my presentation server i know we cannot get it directly.   if we have done it to application layer how can we get it to presentation layer can we code it

  • Keyboard properties crash remote session

    I have a x2go server on Arch and client on Ubuntu. When I open a session, keyboard indicator dies and can not be restarted. When I call keyboard properties from menu it kills the session. The same thing with Nomachine FreeNX. There is any message in

  • Users cannot sign in connected with wifi at home

    Hey I need some urgent help with that issue: My clients report that they can't sign in to Lync app when they conneted to WiFi at home when they are trying to connect Lync through 3G or 4G with "auto detect server" - it does works great! I don't reall

  • BI 200 Business Intelligence Roadmap presentation not providved as promised

    Presenters said it would be posted after the AZ conference.  Where is it?

  • Need some opinions on something

    Basically I'm a huge batman nerd and I want to buy all 4 series of the Animated Series on dvd 3 and 4 were never released in the uk So I have to import those But on eBay someone is selling them (not thay cheap) as region 0 region free On.Amazon they