<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 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    jdom 修改 xml

    Posted on 2009-07-29 23:37 Gavin.lee 閱讀(227) 評論(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一区| 亚洲日韩在线中文字幕第一页| 亚洲AV无码成人网站久久精品大 | 日本人成在线视频免费播放| 免费看小12萝裸体视频国产| 豆国产96在线|亚洲| 亚洲阿v天堂在线2017免费| 一级A毛片免费观看久久精品| 精品国产亚洲男女在线线电影 | 色妞WWW精品免费视频| 亚洲日韩精品无码AV海量| 日韩精品免费一区二区三区| 男男黄GAY片免费网站WWW| 亚洲成A人片在线观看无码3D| eeuss在线兵区免费观看| 亚洲精品无码MV在线观看| 高清一区二区三区免费视频| 亚洲色偷偷av男人的天堂| 欧美大尺寸SUV免费| 丰满亚洲大尺度无码无码专线 | 久久精品国产亚洲av麻豆小说| 国产四虎免费精品视频| 亚洲国产精品无码久久98| 亚洲AV永久无码精品一区二区国产| 久久成人18免费网站| 亚洲理论精品午夜电影| 日本一道高清不卡免费| 精品免费久久久久国产一区| 亚洲精品在线视频观看| 暖暖日本免费在线视频 | 日韩免费一级毛片| 一级一级一级毛片免费毛片| 久久精品国产亚洲AV无码麻豆| 青青草国产免费久久久91| 精品多毛少妇人妻AV免费久久| 91亚洲国产成人久久精品网站| 日韩一区二区在线免费观看 | 相泽南亚洲一区二区在线播放| 国产AV无码专区亚洲精品| 毛片a级毛片免费观看品善网 | 777成影片免费观看|