<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"));
        }

    }
    主站蜘蛛池模板: 日本免费一区尤物| 男女交性永久免费视频播放| 亚洲无线码在线一区观看| 337P日本欧洲亚洲大胆艺术图| 中国在线观看免费高清完整版| 亚洲国产成人精品青青草原| 免费福利视频导航| 亚洲国产精品美女| 99精品国产免费久久久久久下载| 亚洲精品国产福利在线观看| 亚洲视频免费在线播放| 亚洲视频在线免费看| 精品无码免费专区毛片| 亚洲精品天堂在线观看| 成年人在线免费看视频| 亚洲国产午夜精品理论片在线播放 | 精品久久久久久亚洲综合网| 蜜臀91精品国产免费观看 | 国产偷国产偷亚洲高清人 | 亚洲综合精品香蕉久久网| 成人无码区免费A∨直播| 无码欧精品亚洲日韩一区| 777爽死你无码免费看一二区| 久久青青草原亚洲av无码app| h视频在线免费看| 自拍偷区亚洲国内自拍| 日本成人在线免费观看| 国产青草亚洲香蕉精品久久| 亚洲综合激情另类专区| 午夜无码A级毛片免费视频| 亚洲国产精品久久久久秋霞影院| 免费观看成人毛片a片2008| 精品国产亚洲第一区二区三区| 亚洲精品WWW久久久久久| 久久aⅴ免费观看| 亚洲色大成网站www永久男同 | 亚洲日本在线播放| 日韩特黄特色大片免费视频| 久久www免费人成精品香蕉| 亚洲高清中文字幕| mm1313亚洲精品国产|