我检查了一下我的环境变量,发现我的classpath被修改了。我现在把它修改回来以后,运行的时候还有一个错误: 这是一个TransformerException 详细信息是:org.xml.sax.SAXParseException:Premature end of file. 我检查了一下xml文件,结构都很完整的
刚才把错误信息输错了,错误信息是: org.xml.sax.SAXParseException:The processing instruction target matching "[xX][mM][lL]" is not allowed. 这段信息说的是什么意思啊?
import javax.xml.transform.stream.*;
import java.io.*;public class xml2html {
public static void main(String[] args)
throws TransformerException,
TransformerConfigurationException,
FileNotFoundException, IOException
{
TransformerFactory tFactory =
TransformerFactory.newInstance();
Transformer transformer =
tFactory.newTransformer(
new StreamSource("stocks.xsl"));
transformer.transform(
new StreamSource(args[0]),
new StreamResult(new FileOutputStream(
args[1])));
System.out.println
("** The output is written in "+
args[1]+" **");
}
}from http://developer.java.sun.com/developer/technicalArticles/xml/WebAppDev2/#code13
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
try {
TransformerFactory transformerFactory =
TransformerFactory.newInstance(); StreamSource source = new StreamSource("C:\\xmltest\\tiezi.xml");
StreamResult result = new StreamResult("C:\\xmltest\\result.xml");
StreamSource style = new StreamSource("C:\\xmltest\\tiezi.xsl"); Transformer transformer =
transformerFactory.newTransformer(style); transformer.transform(source, result);
return "OK";
} catch (Exception e) {
e.printStackTrace();
return "Failed";
}
=================================================================================
.xml:
=================================================================================
<?xml version="1.0" encoding="UTF-8"?>
<?xml:stylesheet type="text/xsl" href="stock.xsl" version="1.0" encoding="UTF-8"?>
<portfolio>
<stock>
<symbol>SUNW</symbol>
<name>Sun Microsystems</name>
<price>17.1</price>
</stock>
<stock>
<symbol>AOL</symbol>
<name>America Online</name>
<price>51.05</price>
</stock>
<stock>
<symbol>IBM</symbol>
<name>International Business
Machines</name>
<price>116.10</price>
</stock>
<stock>
<symbol>MOT</symbol>
<name>MOTOROLA</name>
<price>15.20</price>
</stock>
</portfolio>=================================================================================
.xsl:
=================================================================================
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:output method="html" indent="yes"/><xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template><xsl:template match="portfolio">
<table border="2" width="50%">
<xsl:for-each select="stock">
<tr>
<td>
<i><xsl:value-of select=
"symbol"/></i>
</td>
<td>
<xsl:value-of select="name"/>
</td>
<td>
<xsl:value-of select="price"/>
</td> </tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
这是一个TransformerException
详细信息是:org.xml.sax.SAXParseException:Premature end of file.
我检查了一下xml文件,结构都很完整的
org.xml.sax.SAXParseException:The processing instruction target matching "[xX][mM][lL]" is not allowed.
这段信息说的是什么意思啊?