最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java使用Jdom實現(xiàn)xml文件寫入操作實例

 更新時間:2015年10月31日 15:54:15   作者:5iasp  
這篇文章主要介紹了java使用Jdom實現(xiàn)xml文件寫入操作的方法,以完整實例形式分析了Jdom針對XML文件寫入操作的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了java使用Jdom實現(xiàn)xml文件寫入操作的方法。分享給大家供大家參考,具體如下:

package com.yanek.demo.xml.test;
import java.io.File;
import java.io.FileWriter;
import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
public class JdomWriteXml {
 /**
 * @param args
 */
 public static void main(String[] args) {
 SAXBuilder sb = new SAXBuilder();
 Element actions = new Element("actions");
 Document document = new Document(actions);
 Element action1 = new Element("action");
 actions.addContent(action1);
 Attribute path_atbt1 = new Attribute("path", "/test");
 Attribute class_atbt1 = new Attribute("class",
  "com.mystruts.demo.LoginAction");
 action1.setAttribute(path_atbt1);
 action1.setAttribute(class_atbt1);
 Element action1_forward1 = new Element("forward");
 action1.addContent(action1_forward1);
 Attribute action1_forward1_name_atbt1 = new Attribute("name", "success");
 Attribute action1_forward1_url_atbt1 = new Attribute("url", "test.jsp");
 action1_forward1.setAttribute(action1_forward1_name_atbt1);
 action1_forward1.setAttribute(action1_forward1_url_atbt1);
 Element action1_forward2 = new Element("forward");
 action1.addContent(action1_forward2);
 Attribute action1_forward1_name_atbt2 = new Attribute("name", "failure");
 Attribute action1_forward1_url_atbt2 = new Attribute("url",
  "failure.jsp");
 action1_forward2.setAttribute(action1_forward1_name_atbt2);
 action1_forward2.setAttribute(action1_forward1_url_atbt2);
 Element action2 = new Element("action");
 actions.addContent(action2);
 Attribute path_atbt2 = new Attribute("path", "/user");
 Attribute class_atbt2 = new Attribute("class",
  "com.mystruts.demo.UserAction");
 action2.setAttribute(path_atbt2);
 action2.setAttribute(class_atbt2);
 Element action2_forward1 = new Element("forward");
 action2.addContent(action2_forward1);
 Attribute action2_forward1_name_atbt1 = new Attribute("name", "success");
 Attribute action2_forward1_url_atbt1 = new Attribute("url", "test.jsp");
 action2_forward1.setAttribute(action2_forward1_name_atbt1);
 action2_forward1.setAttribute(action2_forward1_url_atbt1);
 Element action2_forward2 = new Element("forward");
 action2.addContent(action2_forward2);
 Attribute action2_forward1_name_atbt2 = new Attribute("name", "failure");
 Attribute action2_forward1_url_atbt2 = new Attribute("url",
  "failure.jsp");
 action2_forward2.setAttribute(action2_forward1_name_atbt2);
 action2_forward2.setAttribute(action2_forward1_url_atbt2);
 Attribute root_atbt1 = new Attribute("m", "001");
 actions.setAttribute(root_atbt1);
 try {
  File f1 = new File("mystruts.xml");
  // XMLOutputter xo=new XMLOutputter(" ",true,"GB2312");
  XMLOutputter xo = new XMLOutputter();
  FileWriter fw = new FileWriter(f1);
  xo.output(document, fw);
  fw.close();
 } catch (Exception e) {
  e.printStackTrace();
 }
 // System.out.println(document.toString());
 }
}

生成xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<actions m="001">
<action path="/test" class="com.mystruts.demo.LoginAction">
<forward name="success" url="test.jsp" />
<forward name="failure" url="failure.jsp" />
</action>
<action path="/user" class="com.mystruts.demo.UserAction">
<forward name="success" url="test.jsp" />
<forward name="failure" url="failure.jsp" />
</action>
</actions>

希望本文所述對大家Java程序設(shè)計有所幫助。

相關(guān)文章

  • Spring中@Configuration注解的使用場景

    Spring中@Configuration注解的使用場景

    這篇文章主要介紹了Spring中@Configuration注解的使用場景,@Configuration注解是從Spring?3.0版本開始加入的一個使Spring能夠支持注解驅(qū)動開發(fā)的標(biāo)注型注解,主要用于標(biāo)注在類上,需要的朋友可以參考下
    2023-11-11
  • spring boot + quartz集群搭建的完整步驟

    spring boot + quartz集群搭建的完整步驟

    這篇文章主要給大家介紹了關(guān)于spring boot + quartz集群搭建的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-05-05
  • JVM指令的使用深入詳解

    JVM指令的使用深入詳解

    這篇文章主要給大家介紹了關(guān)于JVM指令使用的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-01-01
  • 談?wù)凥ttpClient使用詳解

    談?wù)凥ttpClient使用詳解

    這篇文章給大家介紹HttpClient使用,httpClient是一個客戶端的http通信實現(xiàn)庫,HttpClient的目標(biāo)是發(fā)送和接收HTTP報文。本文講解的非常詳細(xì),對HttpClient使用感興趣的朋友可以參考下
    2015-10-10
  • 公共POI導(dǎo)出Excel方法詳解

    公共POI導(dǎo)出Excel方法詳解

    這篇文章主要介紹了公共POI導(dǎo)出Excel方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • java關(guān)于字符串的常用API

    java關(guān)于字符串的常用API

    字符串其實就是一串連續(xù)的字符,它是由許多單個字符連接而成的。如多個英文字母所組成的一個英文單詞。字符串中可以包含任意字符,這些字符必須包含在一對雙引號之內(nèi),今天就來介紹字符串常用的API
    2023-05-05
  • Eclipse手動導(dǎo)入DTD文件實現(xiàn)方法解析

    Eclipse手動導(dǎo)入DTD文件實現(xiàn)方法解析

    這篇文章主要介紹了Eclipse手動導(dǎo)入DTD文件實現(xiàn)方法解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-10-10
  • spring緩存自定義resolver的方法

    spring緩存自定義resolver的方法

    這篇文章主要為大家詳細(xì)介紹了spring緩存自定義resolver的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-03-03
  • 常見的排序算法,一篇就夠了

    常見的排序算法,一篇就夠了

    這篇文章主要介紹了一些常用排序算法整理,插入排序算法、直接插入排序、希爾排序、選擇排序、冒泡排序等排序,需要的朋友可以參考下
    2021-07-07
  • SpringMVC中的幾個模型對象

    SpringMVC中的幾個模型對象

    這篇文章主要介紹了SpringMVC中的幾個模型對象,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-12-12

最新評論

阿坝| 扬中市| 黎川县| 慈利县| 资源县| 昭苏县| 德清县| 海门市| 贺兰县| 澄迈县| 松溪县| 海门市| 拉孜县| 永德县| 嘉善县| 富源县| 罗源县| 儋州市| 大兴区| 柘荣县| 大足县| 阿克| 正宁县| 正安县| 正镶白旗| 锡林浩特市| 平山县| 广州市| 平湖市| 青阳县| 广德县| 海伦市| 河南省| 霍城县| 芷江| 阜南县| 黄山市| 永州市| 黄陵县| 仁化县| 天台县|