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

    jdom 修改 xml

    Posted on 2009-07-29 23:37 Gavin.lee 閱讀(227) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): 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>

    操作類(lèi):
    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();
            
    //設(shè)置文檔字符編碼
            format.setEncoding("GB18030");
            
    //設(shè)置縮進(jìn)字符串
            format.setIndent("  ");

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

    }
    主站蜘蛛池模板: 亚洲熟妇无码另类久久久| 亚洲国产精品白丝在线观看| 久久久青草青青国产亚洲免观| 国产91精品一区二区麻豆亚洲| 亚洲一区二区电影| 亚洲中文字幕久久精品无码A | 亚洲福利视频网址| 老司机福利在线免费观看| 亚洲免费人成在线视频观看| 又黄又大又爽免费视频| 久久久亚洲AV波多野结衣 | 91视频免费观看高清观看完整| 18禁免费无码无遮挡不卡网站| 亚洲熟伦熟女新五十路熟妇| 免费的黄色的网站| 人妻视频一区二区三区免费| 国产AV无码专区亚洲AVJULIA| 久久人午夜亚洲精品无码区| 久久久久久精品免费看SSS| 激情97综合亚洲色婷婷五 | 亚洲国产综合精品一区在线播放| 亚洲午夜久久久久久尤物| 少妇性饥渴无码A区免费| 亚洲国产人成精品| 一本色道久久综合亚洲精品蜜桃冫| 国产精品免费观看久久| 黄网站色成年片大免费高清| 亚洲一区无码中文字幕 | 视频一区二区三区免费观看| 亚洲欧洲美洲无码精品VA | 国产免费观看网站| 亚洲av午夜国产精品无码中文字 | 国产综合精品久久亚洲| 一区二区三区观看免费中文视频在线播放 | 亚洲精品天堂成人片?V在线播放| 丝袜捆绑调教视频免费区| 又大又硬又爽免费视频| 在线视频网址免费播放| 亚洲精品自产拍在线观看| a级大片免费观看| 亚洲 欧洲 视频 伦小说|