当前位置: 首页>>代码示例>>Java>>正文


Java SAXTransformerFactory.setAttribute方法代码示例

本文整理汇总了Java中javax.xml.transform.sax.SAXTransformerFactory.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java SAXTransformerFactory.setAttribute方法的具体用法?Java SAXTransformerFactory.setAttribute怎么用?Java SAXTransformerFactory.setAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.transform.sax.SAXTransformerFactory的用法示例。


在下文中一共展示了SAXTransformerFactory.setAttribute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setTraxFactoryAttributes

import javax.xml.transform.sax.SAXTransformerFactory; //导入方法依赖的package包/类
/**
 * Set to the SAX TrAX Factory attributes by inspecting the given parameters
 * for those which are from TrAX namespace
 */
protected void setTraxFactoryAttributes (final SAXTransformerFactory saxtf, final Hashtable <String, Object> params)
{
  // loop over all parameters
  final Enumeration <String> e = params.keys ();
  while (e.hasMoreElements ())
  {
    final String key = e.nextElement ();

    // is this one from TrAX namespace?
    if (key.startsWith (tmp_TRAX_ATTR_NS))
    {

      // it is, remove the namespace prefix and set it to the factory
      final String name = key.substring (tmp_TRAX_ATTR_NS.length ()).toLowerCase ();
      saxtf.setAttribute (name, params.get (key));
      if (CSTX.DEBUG)
        log.debug ("newTHOutOfTrAX(): set factory attribute " + name + "=" + params.get (key));
    }
  }

}
 
开发者ID:phax,项目名称:ph-stx,代码行数:26,代码来源:THTrAXResolver.java

示例2: createTransformerHandler

import javax.xml.transform.sax.SAXTransformerFactory; //导入方法依赖的package包/类
/**
 * Creates a {@link TransformerHandler}.
 * 
 * @param commentHeader the comment header
 * @param rootTag the root tag
 * @param streamResult stream result
 */
public static TransformerHandler createTransformerHandler(String commentHeader, String rootTag,
		StreamResult streamResult, Charset charset)
		throws TransformerFactoryConfigurationError,
		TransformerConfigurationException, SAXException {
	SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance();
       try {
       	tf.setAttribute("indent-number", new Integer(2));
       } catch (Exception e) {
       	// ignore, workaround for JDK 1.5 bug, see http://forum.java.sun.com/thread.jspa?threadID=562510
       }
       TransformerHandler transformerHandler = tf.newTransformerHandler();
       Transformer serializer = transformerHandler.getTransformer();
       serializer.setOutputProperty(OutputKeys.ENCODING, charset.name());
       serializer.setOutputProperty(OutputKeys.METHOD, "xml");
       serializer.setOutputProperty(OutputKeys.INDENT, "yes");
       transformerHandler.setResult(streamResult);
       transformerHandler.startDocument();
       String newline = System.getProperty("line.separator");
       if (newline == null) {
       	newline = "\n";
       }
	commentHeader = (newline + commentHeader).replaceAll("\\n--", newline + " ");
	transformerHandler.characters("\n".toCharArray(), 0, 1);
       transformerHandler.comment(commentHeader.toCharArray(), 0, commentHeader.toCharArray().length);
	transformerHandler.characters("\n".toCharArray(), 0, 1);
	if (rootTag.length() > 0) {
		transformerHandler.startElement("", "", rootTag, null);
	}
       return transformerHandler;
}
 
开发者ID:P15,项目名称:jailer,代码行数:38,代码来源:XmlUtil.java

示例3: createTransformerHandler

import javax.xml.transform.sax.SAXTransformerFactory; //导入方法依赖的package包/类
/**
 * Creates a {@link TransformerHandler}.
 * 
 * @param commentHeader the comment header
 * @param rootTag the root tag
 * @param streamResult stream result
 */
public static TransformerHandler createTransformerHandler(String commentHeader, String rootTag,
		StreamResult streamResult)
		throws TransformerFactoryConfigurationError,
		TransformerConfigurationException, SAXException {
	SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance();
       try {
       	tf.setAttribute("indent-number", new Integer(2));
       } catch (Exception e) {
       	// ignore, workaround for JDK 1.5 bug, see http://forum.java.sun.com/thread.jspa?threadID=562510
       }
       TransformerHandler transformerHandler = tf.newTransformerHandler();
       Transformer serializer = transformerHandler.getTransformer();
       serializer.setOutputProperty(OutputKeys.ENCODING, Charset.defaultCharset().name());
       serializer.setOutputProperty(OutputKeys.METHOD, "xml");
       serializer.setOutputProperty(OutputKeys.INDENT, "yes");
       transformerHandler.setResult(streamResult);
       transformerHandler.startDocument();
       String newline = System.getProperty("line.separator");
       if (newline == null) {
       	newline = "\n";
       }
	commentHeader = (newline + commentHeader).replaceAll("\\n--", newline + " ");
       transformerHandler.comment(commentHeader.toCharArray(), 0, commentHeader.toCharArray().length);
	if (rootTag.length() > 0) {
		transformerHandler.startElement("", "", rootTag, null);
	}
       return transformerHandler;
}
 
开发者ID:domdorn,项目名称:Jailer,代码行数:36,代码来源:XmlUtil.java


注:本文中的javax.xml.transform.sax.SAXTransformerFactory.setAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。