📄 userxml.java
字号:
package cn.myvideosite.xml;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import cn.myvideosite.data.model.bean.UserInfo;
import cn.myvideosite.data.model.services.UserinfoService;
import cn.myvideosite.util.MySuperDate;
public class UserXML {
/**
* @param args 使用xml保存用户
*/
public static void main(String[] args) {
UserInfo user = UserinfoService.findByPerSpace("http://lixianmn.v.56.com");
Element rootElement = new Element("userinfo");
Document myDocument = new Document(rootElement);
rootElement.addContent(new Element("userID").setText(Integer.toString(user.getUserId())));
//设置属性
rootElement.addContent(new Element("nickName").setText(user.getNickName()));
/* Element nickName = new Element("nickName").setText(user.getNickName());
nickName.setAttribute("isChineseName","yes");
rootElement.addContent(nickName);
*/
rootElement.addContent(new Element("sex").setText(user.getSex()));
// rootElement.addContent(new Element("birthday").setText(new MySuperDate(user.getBirthday()).getDateString()));
rootElement.addContent(new Element("place").setText(user.getPlace()));
rootElement.addContent(new Element("age").setText(Integer.toString(user.getAge())));
rootElement.addContent(new Element("vocation").setText(user.getVocation()));
rootElement.addContent(new Element("personalSpace").setText(user.getPersonalSpace()));
rootElement.addContent(new Element("lastTime").setText(new MySuperDate(user.getLastTime()).getDateTimeString()));
rootElement.addContent(new Element("scoreNub").setText(Integer.toString(user.getScoreNub())));
rootElement.addContent(new Element("totalPop").setText(Long.toString(user.getTotalPop())));
XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat().setEncoding("utf-8"));
OutputStream os = null;
try {
os = new FileOutputStream("D:\\javawork\\userinfo\\userinfo.xml");
xmlOut.output(myDocument, os);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally{
try {
if(os != null){
os.close();
os = null;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -