Solved

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

Posted on 2008-10-09
13
186 Views
Last Modified: 2013-11-23
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
Comment
Question by:newbieal
  • 7
  • 6
13 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 22682490
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
 
LVL 4

Author Comment

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

However, it's still trying to validate.
0
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 500 total points
ID: 22686626
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
 
LVL 4

Author Comment

by:newbieal
ID: 22686673
That didn't work either.  I get the this error:

java.net.ConnectException: Connection timed out: connect
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22686757
Please post your code.
0
 
LVL 4

Author Comment

by:newbieal
ID: 22686832

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 500 total points
ID: 22686963
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
 
LVL 4

Author Comment

by:newbieal
ID: 22687023
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
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22687392
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
 
LVL 4

Author Comment

by:newbieal
ID: 22687532
I just don't want it to connect at all.  I want it to ignore the validation of dtd.
0
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 500 total points
ID: 22687573
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
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 500 total points
ID: 22687606
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
 
LVL 4

Author Comment

by:newbieal
ID: 22687790
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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now