Link to home
Start Free TrialLog in
Avatar of newbieal
newbiealFlag for United States of America

asked on

java: xml/html file with doctype trying to connect to site

I've html/xml files that contain the following:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

The Java program that I create parses this file however it won't compile b/c it's trying to visit the w3 site for the DTD info.  Any idea if this function can be turned of in Java/Eclipse?
ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of newbieal

ASKER

Hi mwvisa1,
I added this line:
dbf.setValidating(false);
(dbf being the documentbuildfactory)

However, it's still trying to validate.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That didn't work either.  I get the this error:

java.net.ConnectException: Connection timed out: connect
Please post your code.

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
dbf.setNamespaceAware(false);
dbf.setExpandEntityReferences(false);
			
DocumentBuilder db = dbf.newDocumentBuilder ( );
	    	
Document doc = db.parse ( new File ( "testing.html" ) );
	   
String newinfo = "add this line";
	   
Element root = doc.getDocumentElement ( );
System.out.println ( root.getNodeName ( ) );
NodeList list = root.getChildNodes ( );
for ( int i = 0; i < list.getLength ( ); i++ ) 
{
   if ( list.item ( i ).getNodeName ( ).equals ( "head" ) ) 
{
       list.item ( i ).setTextContent ( newinfo );
}
}
XMLSerializer serializer = new XMLSerializer ( );
serializer.setOutputCharStream ( new java.io.FileWriter ( "testing.html" ) );
serializer.serialize ( doc );

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't understand why you do not get the connection timed out error.  Maybe it just means that your system is able to go out and verify the dtd.

I'm still getting: java.net.ConnectException: Connection timed out: connect

any other ideas? (I really just want to remove the doctype lines in the xml/html files but unfortunately I can't do that - it's a requirement that they stay in)
Yes, it is strange as you have an Internet connection since you are posting here. :)
Should not have anything to do with it, but guess you can check your firewall settings to see.
I just don't want it to connect at all.  I want it to ignore the validation of dtd.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I've suspended all validation in Eclipse and even with that it still tries to connect - arghhh!!!!  I have and am using JDK 1.5