tags:

views:

1145

answers:

3

I have this code:

if (file.exists()) {
  Document doc = builder.parse(file);
  NodeList list = doc.getElementsByTagName("property");
  System.out.println("XML Elements: ");
  for (int ii = 0; ii < list.getLength(); ii++) {

line 2 gives following exception

E:\workspace\test\testDomain\src\com\test\ins\nxg\maps\Right.hbm.xml
...***java.net.SocketException: Operation timed out: connect:could be due to invalid address
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:372)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:233)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:220)
+7  A: 

Parhaps the DocumentBuilder is unsuccessfully trying to access a DTD via a network socket for your XML document?

If there are DTD references in the XML document, try editing them out to prove the cause.

If that fixes your problem, I think you can use an EntityResolver for a more permanent solution, but I've not done it myself.

Brabster
The EntityResolver solution is here: http://stackoverflow.com/questions/243728/
Tomalak
A: 

Try to simplify your problem.

Can you get the code, you have to parse, manually?

If yes, try to parse it. I don't think it's the problem of your DocumentBuilder but your network connection. So you have to ensure, that the DocumentBuilder is able to access every bit of the xml document.

If your manually stored document fails when it is validated, there will be a different error message.

Hope it helps.

furtelwart
A: 

Did you create a new instance of a DocumentBuilderFactory and then create a newDocumentBuilder before you parse the file?

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);

Hope this link helps. It definitely helped me earlier today.

daub815