Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to parse XML file using DocumentBuilder

Tags:

java

parsing

xml

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)

1 Answers

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.

like image 65
brabster Avatar answered Nov 21 '25 12:11

brabster