Bugs item #1847924, was opened at 2007-12-10 15:06
Message generated for change (Tracker Item Submitted) made by Item Submitter
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;
}
}
----------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-dev