• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

org.xml.sax.SAXParseException

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks in advance. I don't know why I'm getting this error in my code.
My files are
XML2HTML.java
----------------------------------------
public static main(String[] args)throws
TransformerConfigurationException, FileNotFoundException, IOException,
TransformerException {
BufferedReader xsl = new BufferedReader(
new FileReader("C:\\Documents and Settings\\Valued Customer\\My "
+ "Documents\\com\\jspPractice\\Test.xsl"));

BufferedReader xml = new BufferedReader(
//new StringReader(new XMLPrintTest().getXML().toString()));
new FileReader("C:\\Documents and Settings\\Valued Customer\\My "
+ "Documents\\com\\jspPractice\\Test.xml"));

BufferedWriter html = new BufferedWriter(new StringWriter());

display(xml);
display(xsl);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource(xsl));
transformer.transform(new StreamSource(xml),
new StreamResult(html));
display(new BufferedReader(new StringReader(html.toString())));
}
Test.xml
-----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.1_02" class="java.beans.XMLDecoder">
<object class="javax.swing.JButton">
<string>Hello world</string>
</object>
</java>
Test.xml
-----------------------------------------
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform" version=
"1.0">
<xsl utput method="html" indent="yes"/>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="java">
<table border="2" width="50%">
<xsl:for-each select="object">
<tr>
<td>
<i><xsl:value-of select=
"string"/></i>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may be able to figure it out if you make use of the information in the exception.

Bill
 
Tom Pepe'
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bill, but after adding the code you suggested, I get the compile error:
XML2HTML.java [36:1] exception org.xml.sax.SAXException is never thrown in body of corresponding try statement
} catch(org.xml.sax.SAXException spe){
^
1 error
Thanks,
Tom
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, your post said you were getting an SAXParseException - where it is being reported?
If in reality you are getting a TransformerException, you can do a getSourceLocator() which returns a SourceLocator object that also has the getLineNumber and getColumnNumber(), etc. methods just like the SAXParseException.
Bill
 
Tom Pepe'
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I don't know why it is acting the way that it is. So, after I caught the TransformerException, per your suggestion, and tried to retrieve the SourceLocator through the getLocator() method of the TransformerException class, it returned a null value. That is to say
catch (TransformerException te){
SourceLocator solo = te.getLocator();

// solo == null.
Sorry, I have tried to work with it but I cannot get my simple XML and XSL examples to work. If you can refer me to a simple example that works, I would be much abliged.
-Tom Pepe
 
Tom Pepe'
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error occured because when referencing the StreamResult Object Constructor I sent it a Writer Object instead of an OutputStream Object. When I replaced the argument to the Constructor it worked.
Thanks,
Tom Pepe
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reporting the solution to the mystery!
Thats an odd one for sure.
 
reply
    Bookmark Topic Watch Topic
  • New Topic