Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

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?
0
newbieal
Asked:
newbieal
  • 7
  • 6
5 Solutions
 
Kevin CrossChief Technology OfficerCommented:
Howdy, newbieal.

If I am not mistaken you have been working with javax.xml.parsers, so you want to take a look at DocumentBuilderFactory: http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/DocumentBuilderFactory.html.

I believe you want to use .setValidating(false).
0
 
newbiealAuthor Commented:
Hi mwvisa1,
I added this line:
dbf.setValidating(false);
(dbf being the documentbuildfactory)

However, it's still trying to validate.
0
 
Kevin CrossChief Technology OfficerCommented:
Not sure as your code and file work on my system just fine without any change in options.  However, you can try this setting:

dbf.setExpandEntityReferences(false);

You can look through the other settings in DocumentBuilderFactory API I linked to above, as maybe I have just not used something that is spelled out in there.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
newbiealAuthor Commented:
That didn't work either.  I get the this error:

java.net.ConnectException: Connection timed out: connect
0
 
Kevin CrossChief Technology OfficerCommented:
Please post your code.
0
 
newbiealAuthor Commented:

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

0
 
Kevin CrossChief Technology OfficerCommented:
Yep, that is what I have with this as imports:
import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
0
 
newbiealAuthor Commented:
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)
0
 
Kevin CrossChief Technology OfficerCommented:
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.
0
 
newbiealAuthor Commented:
I just don't want it to connect at all.  I want it to ignore the validation of dtd.
0
 
Kevin CrossChief Technology OfficerCommented:
And that should definitely be the .setValidating(false) which is why I am not sure why this isn't working for you.

http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/parsers/DocumentBuilderFactory.html#validationCompatibility
0
 
Kevin CrossChief Technology OfficerCommented:
Check your java version, project settings, etc. and make sure nothing weird is going on there.  I am on system with Eclipse/NetBeans and JDK 1.6 and works with setValidating(false).
0
 
newbiealAuthor Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now