?
Solved

Exception using Java and XSLT to parse XHTML input file

Posted on 2006-05-01
8
Medium Priority
?
736 Views
Last Modified: 2013-12-16
I am using the following application:

import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import java.io.*;

public class Transform {

    /**
     * Performs an XSLT transformation, sending the results
     * to System.out.
     */
    public static void main(String[] args) {
      try{       
        if (args.length != 3) {
            System.err.println(
                "Usage: java Transform [xmlfile] [xsltfile]");
            System.exit(1);
        }

        File xmlFile = new File(args[0]);
        File xsltFile = new File(args[1]);
        File xmlDest = new File(args[2]);

        // JAXP reads data using the Source interface
        Source xmlSource = new StreamSource(xmlFile);
        //xmlSource.setSystemId("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd");
        Source xsltSource = new StreamSource(xsltFile);

        // the factory pattern supports different XSLT processors
        TransformerFactory transFact =
                TransformerFactory.newInstance();
        Transformer trans = transFact.newTransformer(xsltSource);
        trans.transform(xmlSource, new StreamResult(xmlDest));
      }
     
      catch (TransformerException e2) {
            System.out.println("Transformer Exception cause = " + e2);    
      }
      catch (Exception e) {
            System.out.println("Exception ==== " + e);  
      }
    }
}

to parse an XHTML input file with a DOCTYPE tag as the first tag as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

I call the application from the command line as follows:
java Transform input.xml stylesheet.xsl output.xml

It throws the following exception:
ERROR:  'Connection timed out: connect'
ERROR:  'com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Connection timed out: connect'
Transformer Exception cause = javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Connection timed out: connect

Please help,
Dave
0
Comment
Question by:gdkinney_2
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16579546
Make sure you are connected to the Internet when you try
0
 

Author Comment

by:gdkinney_2
ID: 16579565
I am connected to the Internet.  I can get to the web from my browser.
0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 16579691
Hi,

xml/xslt file,  If it starts with "http://", Xerces will try to open a HTTP connection to retrieve the content.

R.K
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Accepted Solution

by:
CEHJ earned 672 total points
ID: 16579715
You may have just had a temporary network problem
0
 
LVL 23

Assisted Solution

by:rama_krishna580
rama_krishna580 earned 664 total points
ID: 16579718
And ,

This looks like your used XSLT processor tries to access the XSL stylesheets makeing a network connection and you are offline at this time/ need some proxy settings inorder to get connection to internet.  The best solution is to resolve to local filesystem using the XML catalog system - how to do this depends on your XSLT processor.

R.K
0
 
LVL 92

Assisted Solution

by:objects
objects earned 664 total points
ID: 16581273
Check if you need to use a proxy to access the net. If so, the following shows how to set the proxy in your code:

http://www.javaworld.com/javaworld/javatips/jw-javatip42.html
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn different types of Android Layout and some basics of an Android App.
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

809 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