Bugs item #1847924, was opened at 2007-12-10 16:06 Message generated for change (Comment added) made by filipjirsak You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=116035&aid=1847924&group_id=16035
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Robert (rjamesd) Assigned to: Nobody/Anonymous (nobody) Summary: Exception when parse local XML file as URL with SAXReader Initial Comment: I want to parse a local XML file using SAX reader. However, SAXReader only accepts URLs so I have converted the local path into a URL which I think the SAX reader should accept. I tried this but I get an exception: exception SAXReader.java:484>> read()Connection refused: connect Nested exception: Connection refused: connect SAXReader.java:264>> read() MergeToolDom4j.java:114>> parse() MergeToolDom4j.java:39>> doMerge() MyApp.java:13>> main() Here is the code - I've indicated where the exception is occuring import org.dom4j.Node; import org.dom4j.Element; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.io.SAXReader; import java.net.URL; import java.util.List; import java.io.FileWriter; import java.io.File; public class MergeToolDom4j { public void doMerge() { try { File XmlFile1XmlFile = new File("C:\\file.xml"); if ( XmlFile1XmlFile.canRead() ) { System.out.println("can read XmlFile1XmlFile\n"); } Document XmlFile1 = parse( XmlFile1XmlFile ); // ********* THE EXCEPTION IS HAPPENING HERE *********/ Node rectangleForfile2document = XmlFile1.selectSingleNode( "//[EMAIL PROTECTED]'TAG']" ); Element parentOfRectangleForfile2document = rectangleForfile2document.getParent(); File XmlFile2 = new File("C:\\file2document.xml"); if ( XmlFile2.canRead() ) { System.out.println("can read XmlFile2\n"); } Document file2document = parse( XmlFile2 ); List contentParentOfRectangleForfile2document = parentOfRectangleForfile2document.content(); int indexPositionOfRectangleForfile2document = contentParentOfRectangleForfile2document.indexOf( rectangleForfile2document ); contentParentOfRectangleForfile2document.set( indexPositionOfRectangleForfile2document, file2document ); parentOfRectangleForfile2document.setContent( contentParentOfRectangleForfile2document ); FileWriter out = new FileWriter( "C:\\modifiedLabel.Xml" ); XmlFile1.write( out ); } catch (Exception cause ) { System.out.println("exception"); System.out.println( cause.getMessage() ); System.out.println("\n\n"); System.out.println( cause.getCause() ); System.out.println("\n\n"); StackTraceElement elements[] = cause.getStackTrace(); for (int i = 0, n = elements.length; i < n; i++) { System.err.println(elements[i].getFileName() + ":" + elements[i].getLineNumber() + ">> " + elements[i].getMethodName() + "()"); } } } public Document parse(File file) throws DocumentException { SAXReader reader = new SAXReader(); Document document = reader.read(file); return document; } } ---------------------------------------------------------------------- Comment By: Filip Jirsák (filipjirsak) Date: 2007-12-11 17:46 Message: Logged In: YES user_id=1175071 Originator: NO You can try this: SAXReader reader = new SAXReader(); reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); Document document = reader.read(file); … Or may be another feature or property of Xerces parser – see http://xerces.apache.org/xerces-j/features.html or http://xerces.apache.org/xerces-j/properties.html. If you use standard SAX parser bundled with Sun's JRE, it is just Xerces. ---------------------------------------------------------------------- Comment By: Robert (rjamesd) Date: 2007-12-11 16:40 Message: Logged In: YES user_id=1340913 Originator: YES Yes you are correct about the parser (or something else) trying to read the schema. It is trying to connect to the internet to fetch the DTD. It fails. This failure may be because the machine's firewall does not allow Java apps to do this autonomously. So a solution would be to configure the firewall. Or perhaps Java itself or the parser code is not setup to connect to the internet. The reason why I say you are correct, is because if I remove the schema references from the XML document, then I don't get the exception. Also, reading the schema is not required for what I am doing. So rather than remove the schema, there should be a flag or setting to switch off parsing the DTD. ---------------------------------------------------------------------- Comment By: Filip Jirsák (filipjirsak) Date: 2007-12-10 16:31 Message: Logged In: YES user_id=1175071 Originator: NO I think problem is somewhere in SAX parser – probably if you try read the same file directly with SAX, you would obtain the same exception. Is file.xml some simple file without XML Schema, DTD and so on? May be SAX parser try to read some schema mentioned in file and cannot find them. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=116035&aid=1847924&group_id=16035 ------------------------------------------------------------------------- SF.Net email is sponsored by: Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ dom4j-dev mailing list dom4j-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/dom4j-dev