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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]