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


Java Transformer.setOutputProperty方法代码示例

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


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

示例1: format

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
@Override
public String format(String xml) {
  String formattedString;
  if (xml == null || xml.trim().length() == 0) {
    throw new FormatException("XML empty.");
  }
  try {
    Source xmlInput = new StreamSource(new StringReader(xml));
    StreamResult xmlOutput = new StreamResult(new StringWriter());
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",
        String.valueOf(XML_INDENT));
    transformer.transform(xmlInput, xmlOutput);
    formattedString = xmlOutput.getWriter().toString().replaceFirst(">", ">"
        + SystemCompat.lineSeparator);
  } catch (Exception e) {
    throw new FormatException("Parse XML error. XML string:" + xml, e);
  }
  return formattedString;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:DefaultXmlFormatter.java

示例2: writeDocument

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
 * Write an XML document to a Writer
 */
public static void writeDocument(Document doc, Writer writer)
                                                        throws IOException {
  final Source source = new DOMSource(doc);

  // Prepare the output file
  final Result result = new StreamResult(writer);

  // Write the DOM document to the file
  try {
    final Transformer xformer =
      TransformerFactory.newInstance().newTransformer();
    xformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
    xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); //$NON-NLS-1$ //$NON-NLS-2$
    xformer.transform(source, result);
  }
  catch (TransformerException e) {
    // FIXME: switch to IOException(Throwable) ctor in Java 1.6
    throw (IOException) new IOException().initCause(e);
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:24,代码来源:Builder.java

示例3: synchroGraphicalToXml

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
public void synchroGraphicalToXml(){
	Document doc=this.buildDocument();
	if(doc==null)return;
	TransformerFactory factory=TransformerFactory.newInstance();
	try{
		Transformer transformer=factory.newTransformer();
		transformer.setOutputProperty("encoding","utf-8");
		transformer.setOutputProperty(OutputKeys.INDENT,"yes");				
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		transformer.transform(new DOMSource(doc),new StreamResult(out));
		xmlEditor.getDocumentProvider().getDocument(xmlEditor.getEditorInput()).set(out.toString("utf-8"));
		out.close();
	}catch(Exception ex){
		ex.printStackTrace();
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:17,代码来源:GraphicalEditorPage.java

示例4: toString

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
@Override
public String toString() {
	try {
		TransformerFactory transformerFactory = TransformerFactory.newInstance();
		Transformer transformer = transformerFactory.newTransformer();
		transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
		transformer.setOutputProperty(OutputKeys.INDENT, "yes");

		DOMSource source = new DOMSource(document);
		StreamResult result = new StreamResult(new StringWriter());
		transformer.transform(source, result);
		return result.getWriter().toString();
	} catch (TransformerException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:hivdb,项目名称:sierra,代码行数:17,代码来源:XmlOutput.java

示例5: printDocument

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
public static void printDocument(Node node, OutputStream out) {
  try {
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer transformer = tf.newTransformer();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

    transformer.transform(
        new DOMSource(node),
        new StreamResult(new OutputStreamWriter(out, "UTF-8")));
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:cgraywang,项目名称:TextHIN,代码行数:18,代码来源:SparqlExecutor.java

示例6: printDocument

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
private static void printDocument(Document doc, OutputStream out) throws IOException, TransformerException {
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer transformer = tf.newTransformer();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    OutputStreamWriter osw = new OutputStreamWriter(out, "UTF-8");
    StreamResult sr = new StreamResult(osw);
    transformer.transform(new DOMSource(doc), 
               sr);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:13,代码来源:XMLValidation.java

示例7: formatXML

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
private static String formatXML(String inputXML) {
    try {
        Source xmlInput = new StreamSource(new StringReader(inputXML));
        StreamResult xmlOutput = new StreamResult(new StringWriter());
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        transformer.transform(xmlInput, xmlOutput);
        return xmlOutput.getWriter().toString().replaceFirst(">", ">\n");
    } catch (Exception e) {
        e.printStackTrace();
        return inputXML;
    }
}
 
开发者ID:devzwy,项目名称:KUtils,代码行数:15,代码来源:XmlLog.java

示例8: saveEmitter

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
 * Save a single emitter to the XML file
 * 
 * @param out
 *            The location to which we should save
 * @param emitter
 *            The emitter to store to the XML file
 * @throws IOException
 *             Indicates a failure to write or encode the XML
 */
public static void saveEmitter(OutputStream out, ConfigurableEmitter emitter)
		throws IOException {
	try {
		DocumentBuilder builder = DocumentBuilderFactory.newInstance()
				.newDocumentBuilder();
		Document document = builder.newDocument();

		document.appendChild(emitterToElement(document, emitter));
		Result result = new StreamResult(new OutputStreamWriter(out,
				"utf-8"));
		DOMSource source = new DOMSource(document);

		TransformerFactory factory = TransformerFactory.newInstance();
		Transformer xformer = factory.newTransformer();
		xformer.setOutputProperty(OutputKeys.INDENT, "yes");

		xformer.transform(source, result);
	} catch (Exception e) {
		Log.error(e);
		throw new IOException("Failed to save emitter");
	}
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:33,代码来源:ParticleIO.java

示例9: setCommonOutputProperties

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
public static void setCommonOutputProperties(final Transformer transformer, final boolean indentOutput)
        throws TransformerConfigurationException {
    transformer.setOutputProperty(OutputKeys.METHOD, XML);
    transformer.setOutputProperty(OutputKeys.ENCODING, UTF_8);
    transformer.setOutputProperty(OutputKeys.VERSION, VERSION);
    if (indentOutput) {
        transformer.setOutputProperty(OutputKeys.INDENT, YES);
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3");
    } else {
        transformer.setOutputProperty(OutputKeys.INDENT, NO);
    }
}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:13,代码来源:XMLUtil.java

示例10: writeXml

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
 * @source http://stackoverflow.com/a/7373596
 */
public static void writeXml(Document dom, File xmlFile) throws Exception {
    Transformer t = tf.newTransformer();
    t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
    t.setOutputProperty(OutputKeys.INDENT, "yes");
    t.setOutputProperty(OutputKeys.METHOD, "xml");
    t.setOutputProperty(OutputKeys.VERSION, "1.0");
    t.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    t.transform(new DOMSource(dom), new StreamResult(new FileOutputStream(xmlFile)));
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:13,代码来源:Util.java

示例11: writeDocument

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
public static void writeDocument(Document doc, OutputStream stream) throws TransformerException, IOException {
    TransformerFactory tfactory = TransformerFactory.newInstance();
    Transformer serializer;

    serializer = tfactory.newTransformer();
    //Setup indenting to "pretty print"
    serializer.setOutputProperty(OutputKeys.INDENT, "yes");
    serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
    serializer.transform(new DOMSource(doc), new StreamResult(stream));
    stream.close();
}
 
开发者ID:radsimu,项目名称:UaicNlpToolkit,代码行数:12,代码来源:Utils.java

示例12: nodeToString

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
private static String nodeToString(Node node, StringWriter xmlString) throws Exception, RuntimeException {
    Transformer t = TransformerFactory.newInstance().newTransformer();
    t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    t.setOutputProperty(OutputKeys.INDENT, "no");
    t.transform(new DOMSource(node), new StreamResult(xmlString));
    return xmlString.toString();
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:8,代码来源:TransformationHelper.java

示例13: nodeToText

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
private String nodeToText(Node node) throws TransformerException {
    Transformer trans = TransformerFactory.newInstance().newTransformer();
    trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    StringWriter writer = new StringWriter();
    StreamResult result = new StreamResult(writer);
    trans.transform(new DOMSource(node), result);
    String bodyContent = writer.toString();
    System.out.println("SOAP body content read by SAAJ:"+bodyContent);
    return bodyContent;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:SaajEmptyNamespaceTest.java

示例14: printXml

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
private static void printXml(String tag, String xml, String headString) {
    if (TextUtils.isEmpty(tag)) {
        tag = TAG;
    }
    if (xml != null) {
        try {
            Source xmlInput = new StreamSource(new StringReader(xml));
            StreamResult xmlOutput = new StreamResult(new StringWriter());
            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
            transformer.transform(xmlInput, xmlOutput);
            xml = xmlOutput.getWriter().toString().replaceFirst(">", ">\n");
        } catch (Exception e) {
            e.printStackTrace();
        }
        xml = headString + "\n" + xml;
    } else {
        xml = headString + "Log with null object";
    }

    printLine(tag, true);
    String[] lines = xml.split(LINE_SEPARATOR);
    for (String line : lines) {
        if (!TextUtils.isEmpty(line)) {
            Log.d(tag, "|" + line);
        }
    }
    printLine(tag, false);
}
 
开发者ID:angcyo,项目名称:DexFixDemo,代码行数:31,代码来源:L.java

示例15: writeXml

import javax.xml.transform.Transformer; //导入方法依赖的package包/类
public static void writeXml( Node n, OutputStream os )
        throws TransformerException
{
    TransformerFactory tf=TransformerFactory.newInstance();
    //identity
    Transformer t=tf.newTransformer();
    t.setOutputProperty(OutputKeys.INDENT, "yes");
    t.transform(new DOMSource( n ), new StreamResult( os ));
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:10,代码来源:DomUtil.java


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