當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。