zoukankan      html  css  js  c++  java
  • [每日一学]apache camel|XSLT|SAXON

    最近工作中,用到xslt文件来描述和配置xml文件的转换规则和业务逻辑,开始用jdk自带的TransformerFactory,

    有严重的性能问题

    后来用Saxon 的com.saxonica.config.ProfessionalTransformerFactory,性能提高了10以上。

    example code:(from stackoverfow:http://stackoverflow.com/questions/5516580/using-saxon-and-xslt-to-transform-jdom-xml-documents)

    // Get a TransformerFactory
    System.setProperty("javax.xml.transform.TransformerFactory",
                       "com.saxonica.config.ProfessionalTransformerFactory");
    TransformerFactory tfactory = TransformerFactory.newInstance();
    ProfessionalConfiguration config = (ProfessionalConfiguration)((TransformerFactoryImpl)tfactory).getConfiguration();
    
    // Get a SAXBuilder 
    SAXBuilder builder = new SAXBuilder(); 
    
    //Build JDOM Document
    Document toTransform = builder.build(inputFileHandle); 
    
    //Give it a Saxon wrapper
    DocumentWrapper docw = new DocumentWrapper(toTransform,  inputHandle.getAbsolutePath(), config);
    
    // Compile the stylesheet
    Templates templates = tfactory.newTemplates(new StreamSource(styleSheet));
    Transformer transformer = templates.newTransformer();
    
    // Now do a transformation
    ByteArrayOutputStream outStream = new ByteArrayOutputStream(1024);                  
    transformer.transform(docw, new StreamResult(outStream));
    
    ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
    Document transformed = builder.build(inStream);
    本人精通java高并发,DDD,微服务等技术实践,专注java,rust技术栈。 本人姓名郭莹城,坐标深圳,前IBM架构师、咨询师、敏捷开发技术教练,前IBM区块链研究小组成员、十多年架构设计工作经验,《区块链核心技术与应用》作者之一, 现聚焦于:区块链创投与交易所资源对接和技术咨询。 工作微信&QQ:360369487,区块链创投与交易所资源对接,加我注明:博客园+对接,技术咨询和顾问,加我注明:博客园+顾问。想学习golang和rust的同学,也可以加我微信,备注:博客园+golang或博客园+rust,谢谢!
  • 相关阅读:
    程序员的自我修养 符号修饰 函数签名 以及一个引申的问题: extern "c"
    Spring.NET学习笔记(1)基本依赖注入
    Spring.NET学习笔记(3)注册事件注入
    Spring.NET学习笔记(2)依赖注入细节
    jQuery LigerUI 使用教程入门篇
    Spring.NET学习笔记(5)对象生命周期和创建者对象
    【C#.NET】C#皮肤与主题应用实例
    【VB/C#】Kill进程
    【C#.NET】C#用户控件的使用
    【C#.NET】C#创建多语言网站
  • 原文地址:https://www.cnblogs.com/gyc567/p/5343536.html
Copyright © 2011-2022 走看看