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


Java XMLWriter.close方法代码示例

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


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

示例1: convertXML

import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
/**
 *  Performs XML conversion from ADN to oai_dc format. Characters are encoded as UTF-8.
 *
 * @param  xml        XML input in the 'adn' format.
 * @param  docReader  A lucene doc reader for this record.
 * @param  context    The servlet context where this is running.
 * @return            XML in the converted 'oai_dc' format.
 */
public String convertXML(String xml, XMLDocReader docReader, ServletContext context) {
	getXFormFilesAndIndex(context);
	try {
					
		Transformer transformer = XSLTransformer.getTransformer(transform_file.getAbsolutePath());
		String transformed_content = XSLTransformer.transformString(xml, transformer);
		
		SAXReader reader = new SAXReader();
		Document document = DocumentHelper.parseText(transformed_content);

		// Dom4j automatically writes using UTF-8, unless otherwise specified.
		OutputFormat format = OutputFormat.createPrettyPrint();
		StringWriter outputWriter = new StringWriter();
		XMLWriter writer = new XMLWriter(outputWriter, format);
		writer.write(document);
		outputWriter.close();
		writer.close();
		return outputWriter.toString();			
	} catch (Throwable e) {
		System.err.println("NCS_ITEMToNSDL_DCFormatConverter was unable to produce transformed file: " + e);
		e.printStackTrace();
		return "";
	}
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:33,代码来源:NCS_ITEMToNSDL_DCFormatConverter.java

示例2: transformString

import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
public String transformString (String input, String transform, String tFactory) {
	try {
		File transform_file = new File (xsl_dir, transform);

		Transformer transformer = XSLTransformer.getTransformer(transform_file.getAbsolutePath(), tFactory);
		String transformed_content = XSLTransformer.transformString(input, transformer);
		
		prtln ("\ntransformer: " + transformer.getClass().getName());
		
		SAXReader reader = new SAXReader();
		Document document = DocumentHelper.parseText(transformed_content);

		// Dom4j automatically writes using UTF-8, unless otherwise specified.
		OutputFormat format = OutputFormat.createPrettyPrint();
		StringWriter outputWriter = new StringWriter();
		XMLWriter writer = new XMLWriter(outputWriter, format);
		writer.write(document);
		outputWriter.close();
		writer.close();
		return outputWriter.toString();	
	} catch (Throwable t) {
		prtln (t.getMessage());
		t.printStackTrace();
		return "";
	}
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:27,代码来源:TransformTester.java

示例3: removeHttpConfig

import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
/**
 * 删除配置
 *
 * @param name
 * @throws Exception
 */
public static void removeHttpConfig(String name) throws Exception {
    SAXReader reader = new SAXReader();
    File xml = new File(HTTP_CONFIG_FILE);
    Document doc;
    Element root;
    try (FileInputStream in = new FileInputStream(xml); Reader read = new InputStreamReader(in, "UTF-8")) {
        doc = reader.read(read);
        root = doc.getRootElement();
        Element cfg = (Element) root.selectSingleNode("/root/configs");
        Element e = (Element) root.selectSingleNode("/root/configs/config[@name='" + name + "']");
        if (e != null) {
            cfg.remove(e);
            CONFIG_MAP.remove(name);
        }
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setEncoding("UTF-8");
        XMLWriter writer = new XMLWriter(new FileOutputStream(xml), format);
        writer.write(doc);
        writer.close();
    }
}
 
开发者ID:ajtdnyy,项目名称:PackagePlugin,代码行数:28,代码来源:FileUtil.java

示例4: updateJmx

import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
public static void updateJmx(String jmxFilePath,String csvFilePath,String csvDataXpath) throws IOException, DocumentException {
    SAXReader reader = new SAXReader();
    Document documentNew =  reader.read(new File(jmxFilePath));
    List<Element> list = documentNew.selectNodes(csvDataXpath);
    if( list.size()>1 ){
        System.out.println("报错");
    }else{
        Element e = list.get(0);
        List<Element> eList = e.elements("stringProp");
        for(Element eStringProp:eList){
            if( "filename".equals( eStringProp.attributeValue("name") ) ){
                System.out.println("==========");
                System.out.println( eStringProp.getText() );
                eStringProp.setText(csvFilePath);
                break;
            }
        }
    }

    XMLWriter writer = new XMLWriter(new FileWriter(new File( jmxFilePath )));
    writer.write(documentNew);
    writer.close();

}
 
开发者ID:wang153723482,项目名称:testing_platform,代码行数:25,代码来源:Tools.java

示例5: parseXMLToString

import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
/**
 * xml 2 string
 *
 * @param document xml document
 * @return
 */
public static String parseXMLToString(Document document) {
    Assert.notNull(document);

    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding("UTF-8");
    StringWriter writer = new StringWriter();
    XMLWriter xmlWriter = new XMLWriter(writer, format);
    try {
        xmlWriter.write(document);
        xmlWriter.close();
    } catch (IOException e) {
        throw new RuntimeException("XML解析发生错误");
    }
    return writer.toString();
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:22,代码来源:XmlUtils.java

示例6: transformString

import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
public String transformString (String input, String transform, String tFactory) {
	try {
		File transform_file = new File (xsl_dir, transform);

		Transformer transformer = XSLTransformer.getTransformer(transform_file.getAbsolutePath(), tFactory);
		String transformed_content = XSLTransformer.transformString(input, transformer);
		prtln ("\ntransformer: " + transformer.getClass().getName());
		prtln ("tFactory: " + tFactory);
		
		SAXReader reader = new SAXReader();
		Document document = DocumentHelper.parseText(transformed_content);

		// Dom4j automatically writes using UTF-8, unless otherwise specified.
		OutputFormat format = OutputFormat.createPrettyPrint();
		StringWriter outputWriter = new StringWriter();
		XMLWriter writer = new XMLWriter(outputWriter, format);
		writer.write(document);
		outputWriter.close();
		writer.close();
		return outputWriter.toString();	
	} catch (Throwable t) {
		prtln (t.getMessage());
		t.printStackTrace();
		return "";
	}
}
 
开发者ID:NCAR,项目名称:dls-repository-stack,代码行数:27,代码来源:TransformTester.java

示例7: documentToString

import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
/**
 * Devuelve la representaci�n de un Document XML en String bien formateado
 * y con codificaci�n UTF-8.
 * @param doc Documento.
 * @return string representando el documento formateado y en UTF-8.
 */
private String documentToString(Document doc) {
    String result = null;
    StringWriter writer = new StringWriter();
    OutputFormat of = OutputFormat.createPrettyPrint();
    of.setEncoding("UTF-8");
    XMLWriter xmlWriter = new XMLWriter(writer, of);
    try {
        xmlWriter.write(doc);
        xmlWriter.close();
        result = writer.toString();
    } catch (IOException e) {
        log.error("Error escribiendo xml", e);
    }
    return result;
}
 
开发者ID:GovernIB,项目名称:sistra,代码行数:22,代码来源:InstanciaTelematicaProcessorEJB.java

示例8: doc2XmlFile

import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
/**
 * doc2XmlFile
 * 将Document对象保存为一个xml文件到本地
 * @return true:保存成功  flase:失败
 * @param filename 保存的文件名
 * @param document 需要保存的document对象
 */
public static boolean doc2XmlFile(Document document,String filename)
{
   boolean flag = true;
   try{
         /* 将document中的内容写入文件中 */
         //默认为UTF-8格式,指定为"GB2312"
         OutputFormat format = OutputFormat.createPrettyPrint();
         format.setEncoding("GB2312");
         XMLWriter writer = new XMLWriter(new FileWriter(new File(filename)),format);
         writer.write(document);
         writer.close();            
     }catch(Exception ex){
         flag = false;
         ex.printStackTrace();
     }
     return flag;      
}
 
开发者ID:codeWatching,项目名称:codePay,代码行数:25,代码来源:XmlUtil.java

示例9: testExpandEmptyElements

import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
@Test
public void testExpandEmptyElements() throws IOException {
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("root");
    Element id = root.addElement("id");
    id.addText("1");

    root.addElement("empty");

    OutputFormat xmlFormat = new OutputFormat();
    // OutputFormat.createPrettyPrint();
    xmlFormat.setSuppressDeclaration(true);
    xmlFormat.setEncoding("UTF-8");
    // If this is true, elements without any child nodes
    // are output as <name></name> instead of <name/>.
    xmlFormat.setExpandEmptyElements(true);


    StringWriter out = new StringWriter();
    XMLWriter xmlWriter = new XMLWriter(out, xmlFormat);
    xmlWriter.write(document);
    xmlWriter.close();

    assertEquals("<root><id>1</id><empty></empty></root>", out.toString());
}
 
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:26,代码来源:Dom4jTest.java

示例10: writeTmpXmiFIle

import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
/**
 * Write the document based on DOM4J to the tmp file in disk
 * 
 * @param document
 *            document of SysML based on DOM4j
 * @throws IOException
 */
public static String writeTmpXmiFIle(Document document) throws IOException {
	String method = "FileHandler_writeTmpXmiFIle(): ";
	long startTime = System.currentTimeMillis();
	MyLog.info(method + "start");

	File fixedFile = FileHandler.createTempFileInOS(FIXED_FILE_NAME);
	String targetPath = fixedFile.getPath();

	XMLWriter writer = new XMLWriter(new FileWriter(targetPath));
	writer.write(document);
	writer.close();

	MyLog.info(method + "end with " + (System.currentTimeMillis() - startTime) + " millisecond");
	MyLog.info();
	
	return targetPath;
}
 
开发者ID:ZhengshuaiPENG,项目名称:org.lovian.eaxmireader,代码行数:25,代码来源:FileHandler.java

示例11: convertDocumentToByteArray

import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
/**
 * Convert a dom4j xml document to a byte[].
 * 
 * @param document
 *            The document to convert.
 * @return A <code>byte[]</code> representation of the xml document.
 * @throws IOException
 *             If an exception occurs when converting the document.
 */
public byte[] convertDocumentToByteArray(Document document)
		throws IOException {
	ByteArrayOutputStream stream = new ByteArrayOutputStream();
	XMLWriter writer = new XMLWriter(stream);
	byte[] documentAsByteArray = null;
	try {
		writer.write(document);
	} finally {
		writer.close();
		stream.flush();
		stream.close();
	}
	documentAsByteArray = stream.toByteArray();
	return documentAsByteArray;
}
 
开发者ID:powermock,项目名称:powermock-examples-maven,代码行数:25,代码来源:AbstractXMLRequestCreatorBase.java

示例12: updateStrings

import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
/**
 * 修改strings.xml文件内容
 *
 * @param file    strings文件
 * @param strings 修改的值列表
 */
private void updateStrings(File file, List<Strings> strings) {
    try {
        if (strings == null || strings.isEmpty()) {
            return;
        }
        Document document = new SAXReader().read(file);
        List<Element> elements = document.getRootElement().elements();
        elements.forEach(element -> {
            final String name = element.attribute("name").getValue();
            strings.forEach(s -> {
                if (s.getName().equals(name)) {
                    element.setText(s.getValue());
                    callback("修改 strings.xml name='" + name + "' value='" + s.getValue() + "'");
                }
            });
        });
        XMLWriter writer = new XMLWriter(new FileOutputStream(file));
        writer.write(document);
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:spacetimeme,项目名称:ApkCustomizationTool,代码行数:30,代码来源:Command.java

示例13: updateBools

import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
/**
 * 修改bools.xml文件内容
 *
 * @param file  bools文件
 * @param bools 修改的值列表
 */
private void updateBools(File file, List<Bools> bools) {
    try {
        if (bools == null || bools.isEmpty()) {
            return;
        }
        Document document = new SAXReader().read(file);
        List<Element> elements = document.getRootElement().elements();
        elements.forEach(element -> {
            final String name = element.attribute("name").getValue();
            bools.forEach(s -> {
                if (s.getName().equals(name)) {
                    element.setText(s.getValue());
                    callback("修改 bools.xml name='" + name + "' value='" + s.getValue() + "'");
                }
            });
        });
        XMLWriter writer = new XMLWriter(new FileOutputStream(file));
        writer.write(document);
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:spacetimeme,项目名称:ApkCustomizationTool,代码行数:30,代码来源:Command.java

示例14: FileOutputStream

import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
/**方法(公共)<br>
* 名称:    save<br>
* 描述:    储存文档对象为本地文件(指定文档)<br>
* @param  doc - 指定文档
* @param  savePath - 储存路径
* @return boolean - 是否成功
*/public boolean save(Document doc,String savePath)
{
    boolean isSuccess=false;
    try
    {
        FileOutputStream output=new FileOutputStream(savePath);
        OutputFormat format=new OutputFormat("",true,"UTF-8");
        XMLWriter writer=new XMLWriter(output,format);
        writer.write(doc);
        writer.close();
        isSuccess=true;
    }
    catch(IOException ex)
    {
        isSuccess=false;
    }
    return isSuccess;
}
 
开发者ID:ProteanBear,项目名称:ProteanBear_Java,代码行数:25,代码来源:XMLProcessor.java

示例15: writeToXML

import org.dom4j.io.XMLWriter; //导入方法依赖的package包/类
public static boolean writeToXML(Document document, String tempPath) {
	try {
		// 使用XMLWriter写入,可以控制格式,经过调试,发现这种方式会出现乱码,主要是因为Eclipse中xml文件和JFrame中文件编码不一致造成的
		OutputFormat format = OutputFormat.createPrettyPrint();
		format.setEncoding(EncodingUtil.CHARSET_UTF8);
		// format.setSuppressDeclaration(true);//这句话会压制xml文件的声明,如果为true,就不打印出声明语句
		format.setIndent(true);// 设置缩进
		format.setIndent("	");// 空行方式缩进
		format.setNewlines(true);// 设置换行
		XMLWriter writer = new XMLWriter(new FileWriterWithEncoding(new File(tempPath), EncodingUtil.CHARSET_UTF8), format);
		writer.write(document);
		writer.close();
	} catch (IOException e) {
		e.printStackTrace();
		MyLogger.logger.error("写入xml文件出错!");
		return false;
	}
	return true;
}
 
开发者ID:shijiebei2009,项目名称:CEC-Automatic-Annotation,代码行数:20,代码来源:WriteToXMLUtil.java


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