我正在使用XSL将我的XML文件配置为更小的XML.我的代码片段是这样的:
public class MessageTransformer {
public static void main(String[] args) {
try {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer (new StreamSource("sample.xsl"));
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform(new StreamSource ("sample.xml"),
new StreamResult( new FileOutputStream("sample.xml"))
);
}
catch (Exception e) {
e.printStackTrace( );
}
}
}
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误
ERROR: 'Premature end of file.'
ERROR: 'com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Premature end of file.'
Run Code Online (Sandbox Code Playgroud)
当我使用XSL文件手动转换XML时,我没有任何问题.但是使用这个JAVA文件我无法转换.
会出现什么问题?
我尝试在Spring中使用JDBC编写事务管理器.
我的app-servlet.xml
<!-- JDBC Config -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}"
p:username="${jdbc.username}"
p:password="${jdbc.password}" />
<!-- dataSource TransactionManager -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="UserDAOImpl" class="com.project.dao.impl.UserDAOImpl">
<property name="transactionManager" ref="transactionManager"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
我的UserDAOImpl.java
public class UserDAOImpl implements UserDAO {
//transaction manager
private DataSourceTransactionManager transactionManager;
private JdbcTemplate jdbcTemplate;
public UserDAOImpl() {
super();
DataSource dataSource = transactionManager.getDataSource();
jdbcTemplate = new JdbcTemplate(dataSource);
}
public void setTransactionManager(DataSourceTransactionManager transactionManager) {
this.transactionManager = transactionManager;
}
....
}
Run Code Online (Sandbox Code Playgroud)
即使我已经transactionManager在我的应用程序,servlet的豆,UserDAOImpl不会因为instatiated transactionManager是 …
我有这个XSL代码,我想配置字符串.但是我还没有得到配置的字符串.可能是什么事?
<xsl:param name="topicId"></xsl:param>
<xsl:param name="topicName"/>
<xsl:attribute-set name="attrTopic">
<xsl:attribute name="id">
<xsl:value-of select="/message/file/@name[substring-after($topicId,'-')]"/>
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="/message/file/@name[substring-before(' ',$topicId)]"/>
</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="attrVars">
</xsl:attribute-set>
Run Code Online (Sandbox Code Playgroud)
$ topicId来自我的Java文件.总之,我试图在XSL中将此字符串"1010-Text"分别转换为"1010"和"Text"
我已经找到了其他类似问题的答案,但看不到有用的..
我有一个用mysql db生成的html表.我在我的php文件中使用这个片段保存为excel
$file="program.xls";
header('Content-Type: text/html');
$table = $_POST['tablehidden'];//i get this from another php file.It is HTML table
header("Content-type: application/x-msexcel"); //tried adding charset='utf-8' into header
header("Content-Disposition: attachment; filename=$file");
echo $table;
如何解决字符集和样式问题?我看过phpexcel但看不到直接包含表的方法.