package com.rocwing.server;import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;public class MapsXmlServices {
public void addXml(String getid , String getname,String getGb ,String getGp,String gettell,String getaddress,String getwww){
 Element rootElt=null;
SAXBuilder sb=new SAXBuilder();
Document doc=null;
try {
doc=sb.build(Thread.currentThread().getContextClassLoader().getResourceAsStream("google.xml"));
rootElt=doc.getRootElement();

} catch (JDOMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//写文件
XMLOutputter out=new XMLOutputter();
try {

Element elt=new Element("google");

Element id1=new Element("id");
id1.addContent(getid);
Element id2=new Element("name");
id2.addContent(getname);
Element id3=new Element("Gb");
id3.addContent(getGb);
Element id4=new Element("Gp");
id4.addContent(getGp);
Element id5=new Element("tel");
id5.addContent(gettell);
Element id6=new Element("address");
id6.addContent(getaddress);

Element id7=new Element("www");
id7.addContent(getwww);


elt.addContent(id1);
elt.addContent(id2);
elt.addContent(id3);
elt.addContent(id4);
elt.addContent(id5);
elt.addContent(id6);
elt.addContent(id7);


doc.getRootElement().addContent(elt);

out.output(doc, new FileOutputStream("d:/google.xml"));

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("完成");
}

public static void main(String[] args) {
MapsXmlServices d = new MapsXmlServices();
d.addXml("12", "getname", "getGb", "getGp", "gettell", "getaddress", "getwww");
}
}