You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Jianlin Chang <ch...@platform.com> on 2003/09/10 18:31:36 UTC

DOM parser problem with handling Windows UNC path for XML and DTD file

It looks that there are problems with handling Windows UNC path (a path in the format of \\computer\share\filename).  I would like to seek help on how to solve the problem.

For the DocumentBuilder.parse() method, if a UNC path name is specified as the parameter, it will fail will error 'java.net.MalformedURLException: no protocol'.
I have to use 'DocumentBuilder.parse(new File(uncPath))'.  Then it got problems with find DTD file that the XML file uses:
<!DOCTYPE Users SYSTEM "Users.dtd">
The error is:
'Connection refused: connect'.  From the stack trace, it looks that it trys to find the DTD file using FTP.

I tried two approaches.  1. set validating to false, but it looks that it still try to find the DTD file.  2. Using EntityResolver to resolve the DTD file, but it looks that the EntityResolver is never called (the print statement doesn't print anything).  Why is this not called?

How can I solve the problem?

The sample code is enclosed.

xerces-j version I used is 2.0.2.

Thanks.


import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.Serializer;
import org.apache.xml.serialize.SerializerFactory;
import org.apache.xml.serialize.XMLSerializer;

public class TestDOM {
    static public void main(String args[])
    {
	try {
	    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
	    docBuilderFactory.setValidating(false);
	    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
	    docBuilder.setEntityResolver(new MyEntityResolver());
// 	    Document m_domDocument = docBuilder.parse(args[0]);
	    Document m_domDocument = docBuilder.parse(new java.io.File(args[0]));
	} catch (ParserConfigurationException exn) {
	    System.err.println("Got ParserConfigurationException: " + exn.getMessage());
	} catch (SAXException exn) {
	    System.err.println("Got SAXException: " + exn.getMessage());
	} catch (java.io.IOException exn) {
	    System.err.println("Got IOException: " + exn.getMessage());
	    exn.printStackTrace();
	}
    }
}

class MyEntityResolver implements EntityResolver {
   public InputSource resolveEntity(String publicId, String systemId)
       throws SAXException, java.io.IOException
   {
       System.out.println("MyEntityResolver: " + systemId);
       java.io.FileInputStream fs = new java.io.FileInputStream(systemId);
       return new InputSource(fs);
   }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: DOM parser problem with handling Windows UNC path for XML and DTD file

Posted by Joseph Kesselman <ke...@us.ibm.com>.



Try putting file:/// in front of the UNC path, to make it a legal
local-directory-system URI...

______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org