當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLWriter.write方法代碼示例

本文整理匯總了Java中org.dom4j.io.XMLWriter.write方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLWriter.write方法的具體用法?Java XMLWriter.write怎麽用?Java XMLWriter.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.dom4j.io.XMLWriter的用法示例。


在下文中一共展示了XMLWriter.write方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: printXML

import org.dom4j.io.XMLWriter; //導入方法依賴的package包/類
/**
 * 打印XML
 *
 * @param document
 */
protected void printXML(Document document) {
    if (log.isInfoEnabled()) {
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setExpandEmptyElements(true);
        format.setSuppressDeclaration(true);
        StringWriter stringWriter = new StringWriter();
        XMLWriter writer = new XMLWriter(stringWriter, format);
        try {
            writer.write(document);
            log.info(stringWriter.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
開發者ID:minlia-projects,項目名稱:minlia-iot,代碼行數:21,代碼來源:AbstractApiComponent.java

示例2: doWork

import org.dom4j.io.XMLWriter; //導入方法依賴的package包/類
public void doWork(XmlPullParser reader, XMLWriter writer)
	throws Exception
{
	// Deal with the contents of the tag
	int eventType = reader.getEventType();
	while (eventType != XmlPullParser.END_TAG) 
       {
		eventType = reader.next();
		if (eventType == XmlPullParser.START_TAG) 
		{
			ImportFileUpdater.this.outputCurrentElement(reader, writer, new OutputChildren());
		}
		else if (eventType == XmlPullParser.TEXT)
		{
			// Write the text to the output file
			writer.write(reader.getText());
		}
       }			
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:20,代碼來源:ImportFileUpdater.java

示例3: 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

示例4: fileSource

import org.dom4j.io.XMLWriter; //導入方法依賴的package包/類
public void fileSource(HttpServletRequest req, HttpServletResponse resp) throws Exception {
	String path=req.getParameter("path");
	path=Utils.decodeURL(path);
	InputStream inputStream=repositoryService.readFile(path,null);
	String content=IOUtils.toString(inputStream,"utf-8");
	inputStream.close();
	String xml=null;
	try{
		Document doc=DocumentHelper.parseText(content);
		OutputFormat format=OutputFormat.createPrettyPrint();
		StringWriter out=new StringWriter();
		XMLWriter writer=new XMLWriter(out, format);
		writer.write(doc);
		xml=out.toString();
	}catch(Exception ex){
		xml=content;
	}
	Map<String,Object> result=new HashMap<String,Object>();
	result.put("content", xml);
	writeObjectToJson(resp, result);
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:22,代碼來源:FrameServletHandler.java

示例5: 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

示例6: generateError

import org.dom4j.io.XMLWriter; //導入方法依賴的package包/類
/**
 * Generates the error tag
 * 
 * @param xml XMLWriter
 */
protected void generateError(XMLWriter xml)
{
    try
    {
        // Output the start of the error element
        Attributes nullAttr = getDAVHelper().getNullAttributes();

        xml.startElement(WebDAV.DAV_NS, WebDAV.XML_ERROR, WebDAV.XML_NS_ERROR, nullAttr);
        // Output error
        xml.write(DocumentHelper.createElement(WebDAV.XML_NS_CANNOT_MODIFY_PROTECTED_PROPERTY));

        xml.endElement(WebDAV.DAV_NS, WebDAV.XML_ERROR, WebDAV.XML_NS_ERROR);
    }
    catch (Exception ex)
    {
        // Convert to a runtime exception
        throw new AlfrescoRuntimeException("XML processing error", ex);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:25,代碼來源:PropPatchMethod.java

示例7: 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

示例8: 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

示例9: formatXML

import org.dom4j.io.XMLWriter; //導入方法依賴的package包/類
/**
 * 格式化XML
 * 
 * @param inputXML
 * @return
 * @throws Exception
 */
public static String formatXML(String inputXML) throws Exception {
	Document doc = DocumentHelper.parseText(inputXML);
	StringWriter out = null;
	if (doc != null) {
		try {
			OutputFormat format = OutputFormat.createPrettyPrint();
			out = new StringWriter();
			XMLWriter writer = new XMLWriter(out, format);
			writer.write(doc);
			writer.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			out.close();
		}

		return out.toString();
	}

	return inputXML;
}
 
開發者ID:xmomen,項目名稱:dms-webapp,代碼行數:29,代碼來源:HttpClient.java

示例10: 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

示例11: 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,項目名稱:dls-repository-stack,代碼行數:33,代碼來源:NCS_ITEMToNSDL_DCFormatConverter.java

示例12: 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

示例13: updateHbmCfg

import org.dom4j.io.XMLWriter; //導入方法依賴的package包/類
/**
 * 把hbm.xml的路徑加入到cfg.xml的mapping結點
 *
 * @param cfg.xml的路徑
 * @param hbm.xml的路徑
 */
public static void updateHbmCfg(URL url,String hbm)
{
	try
	{
		SAXReader reader = new SAXReader();
		Document doc = reader.read(url);
		Element element = (Element)doc.getRootElement()
		.selectSingleNode("session-factory");
		
		Element hbmnode = element.addElement("mapping");
		hbmnode.addAttribute("resource", hbm);
		String filepath = url.getFile();
		if (filepath.charAt(0)=='/')
			filepath = filepath.substring(1);
		FileOutputStream outputstream = new FileOutputStream(filepath);
		XMLWriter writer = new XMLWriter(outputstream);
		writer.write(doc);
		outputstream.close();
	}
	catch (Exception e)
	{
		e.printStackTrace();
	}
}
 
開發者ID:RayleighChen,項目名稱:Improve,代碼行數:31,代碼來源:HibernateUtil.java

示例14: 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

示例15: perform

import org.dom4j.io.XMLWriter; //導入方法依賴的package包/類
public void perform(TaskRequest req, TaskResponse res) {

		File f = new File((String) file.evaluate(req, res));
		if (f.getParentFile() != null) {
			// Make sure the necessary directories are in place...
			f.getParentFile().mkdirs();
		}
		
		try {
			XMLWriter writer = new XMLWriter(new FileOutputStream(f), OutputFormat.createPrettyPrint());
			writer.write((Node) node.evaluate(req, res));
		} catch (Throwable t) {
			String msg = "Unable to write the specified file:  " + f.getPath();
			throw new RuntimeException(msg, t);
		}
				
	}
 
開發者ID:drewwills,項目名稱:cernunnos,代碼行數:18,代碼來源:WriteDocumentTask.java


注:本文中的org.dom4j.io.XMLWriter.write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。