newbieal
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?
<!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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That didn't work either. I get the this error:
java.net.ConnectException: Connection timed out: connect
java.net.ConnectException:
Please post your code.
ASKER
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 );
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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)
I'm still getting: java.net.ConnectException:
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.
Should not have anything to do with it, but guess you can check your firewall settings to see.
ASKER
I just don't want it to connect at all. I want it to ignore the validation of dtd.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
ASKER
I added this line:
dbf.setValidating(false);
(dbf being the documentbuildfactory)
However, it's still trying to validate.