首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

xsl xml归并

2012-09-23 
xsl xml合并public String mergeXml(String xml, String xslt) {if (LOG.isDebugEnabled()) {LOG.debug(x

xsl xml合并
public String mergeXml(String xml, String xslt) {

if (LOG.isDebugEnabled()) {
LOG.debug("xml:" + xml + "\n xsl:" + xslt);
}

ByteArrayOutputStream out = null;
try {
TransformerFactory transformerFactory = TransformerFactory
.newInstance();

Source xslSource = new StreamSource(new StringReader(xslt));
Templates templates = transformerFactory.newTemplates(xslSource);
Transformer transformer = templates.newTransformer();
Source xmlSource = new StreamSource(new StringReader(xml));
out = new ByteArrayOutputStream();
Result outputTarget = new StreamResult(out);
transformer.transform(xmlSource, outputTarget);

return new String(out.toByteArray(), "utf-8");
} catch (TransformerConfigurationException e) {
LOG.warn("合并错xml:" + xml + "\n xsl:" + xslt + e);
} catch (TransformerException e) {
LOG.warn("合并错xml:" + xml + "\n xsl:" + xslt + e);
} catch (UnsupportedEncodingException e) {
LOG.warn("合并时编码输出错" + xml + "\n xsl:" + xslt + e);
} catch (NullPointerException e) {
LOG.warn(e);
} finally {

if (out != null) {
try {
out.close();
} catch (IOException e) {
LOG.warn("连接关闭发生错误");
}
}
}
return null;

}

热点排行