<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    無線&移動互聯網技術研發

    換位思考·····
    posts - 19, comments - 53, trackbacks - 0, articles - 283
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    jdom 修改 xml

    Posted on 2009-07-29 23:37 Gavin.lee 閱讀(222) 評論(0)  編輯  收藏 所屬分類: xml doc 操作
    修改前:
    <?xml version="1.0" encoding="GBK"?> 
    <bookList> 
       
    <book> 
           
    <name>Java</name> 
           
    <author>張三</author> 
           
    <publishDate>2002-6-6</publishDate> 
           
    <price>35.0</price> 
       
    </book> 
       
    <book> 
           
    <name>XML</name> 
           
    <author>李四</author> 
           
    <publishDate>2002-9-16</publishDate> 
           
    <price>92.0</price> 
       
    </book> 
    </bookList>
    修改后:
    <?xml version="1.0" encoding="UTF-8"?>
    <bookList> 
       
    <book hot="true"> 
           
    <name>Java</name> 
           
    <author>redtroy</author> 
           
    <publishDate>2002-6-6</publishDate> 
           
    <price>100.0</price> 
       
    </book> 
       
    <book> 
           
    <name>XML</name> 
           
    <author>李四</author> 
           
    <publishDate>2002-9-16</publishDate> 
           
    <price>92.0</price> 
       
    </book> 
    </bookList>

    操作類:
    package com.Gavin.xml;

    import org.jdom.*;
    import org.jdom.output.*;
    import org.jdom.input.*;
    import java.io.*;
    import java.util.List;

    public class JDOMDemo {

        
    public static void main(String[] args) throws Exception {
            SAXBuilder sb 
    = new SAXBuilder();
            Document doc 
    = sb.build(new FileInputStream("d:/exampleA.xml"));
            Element root 
    = doc.getRootElement();
            List books 
    = root.getChildren();
            Element book 
    = (Element) books.get(0);
            Attribute newattribute 
    = new Attribute("hot""true");
            book.setAttribute(newattribute);
            Element author 
    = (Element) book.getChild("author");
            author.setText(
    "redtroy");
            Element price 
    = book.getChild("price");
            price.setText(Float.toString(
    100));

            Format format 
    = Format.getCompactFormat();
            
    //設置文檔字符編碼
            format.setEncoding("GB18030");
            
    //設置縮進字符串
            format.setIndent("  ");

    //        XMLOutputter out = new XMLOutputter();
            XMLOutputter out = new XMLOutputter(format);
            out.output(doc, 
    new FileOutputStream("d:/exampleB.xml"));
        }

    }
    主站蜘蛛池模板: 久久亚洲精品中文字幕| 亚洲AV无码国产丝袜在线观看| 亚洲VA综合VA国产产VA中| 中国亚洲呦女专区| 免费三级毛片电影片| 2019亚洲午夜无码天堂| 国产一精品一AV一免费孕妇| 67194在线午夜亚洲| 天天摸天天操免费播放小视频| 亚洲 日韩经典 中文字幕 | 亚洲欧洲日产国码无码久久99| 三级片免费观看久久| 国产自偷亚洲精品页65页| 99精品免费视品| 久久久久久亚洲精品| 2021在线永久免费视频| 自拍日韩亚洲一区在线| 精品国产免费观看久久久| 免费夜色污私人影院网站电影| 国产亚洲美日韩AV中文字幕无码成人 | 亚洲三级电影网站| 中文字幕无码播放免费| 亚洲AV无码一区二区三区性色 | 精品一区二区三区免费毛片爱| 亚洲美女aⅴ久久久91| 四虎成人免费网站在线| 一级午夜免费视频| 久久亚洲日韩精品一区二区三区| 18禁无遮挡无码网站免费| 黄色毛片免费网站| 亚洲人成在线影院| 免费观看的av毛片的网站| 国产特黄一级一片免费| 日本一道综合久久aⅴ免费| 一级女性全黄生活片免费看| 18gay台湾男同亚洲男同| 国产精品无码一二区免费| 国产一区二区三区免费观在线| 亚洲国产精品综合久久网各| 久久福利青草精品资源站免费| 亚洲精品高清国产麻豆专区|