有现成的源代码吗?
因为我对xml一窍不通,但还要尽快完成任务。我没时间研究啦。
谢谢!

解决方案 »

  1.   

    用你先去搞个JDOM的包,让后运行我写的代码 ,假设你的配置文件文件名为test.xml是放在C盘根目录下的,代码如下:import org.jdom.*;
    import org.jdom.output.*;
    import org.jdom.input.*;
    import java.io.*;
    public class xml{
            public void toXml() throws JDOMException,IOException{
              SAXBuilder saxBuilder=new SAXBuilder(false);
              saxBuilder.setExpandEntities(false);
              File file = new File("c:\\test.xml");
              Document doc =saxBuilder.build(new File("c:\\test.xml"));
              Element elem=doc.getRootElement();
              //System.out.println(elem.toString());
             elem.getChild("Collectors").getChild("Collector").getAttribute("HostIP").setValue("192.168.0.1");
             elem.getChild("Collectors").getChild("Collector").getAttribute("PortID").setValue("100000");
             Element elem1 = (Element)elem.clone();         Document Doc=new Document(elem1);
             XMLOutputter XMLOut = new XMLOutputter();
             XMLOut.setEncoding("BIG5");
             XMLOut.setNewlines(true);
             file.delete();
             XMLOut.output(Doc,new FileOutputStream("c:\\test"+".xml"));
            }
            public static void main(String args[]){                        xml x = new xml();
                    try{
                            x.toXml();
                    }catch(Exception e){}
            }
    }别忘了给分哦~:)
      

  2.   

    用jdom类似的问题用google搜索一下就有了