aspose file tools*
The moose likes XML and Related Technologies and the fly likes org.xml.sax.SAXParseException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "org.xml.sax.SAXParseException" Watch "org.xml.sax.SAXParseException" New topic
Author

org.xml.sax.SAXParseException

Tom Pepe'
Greenhorn

Joined: Nov 02, 2002
Posts: 20
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>
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
You may be able to figure it out if you make use of the information in the exception.

Bill
Tom Pepe'
Greenhorn

Joined: Nov 02, 2002
Posts: 20
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
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
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

Joined: Nov 02, 2002
Posts: 20
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

Joined: Nov 02, 2002
Posts: 20
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
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Thanks for reporting the solution to the mystery!
Thats an odd one for sure.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: org.xml.sax.SAXParseException