⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 albuminfoxml.java

📁 模拟的土豆网视频网站
💻 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.AlbumInfo;
import cn.myvideosite.data.model.services.AlbumInfoService;
import cn.myvideosite.util.MySuperDate;

public class AlbumInfoXML {

	/**
	 * @param args 使用xml保存专辑
	 */
	public static void main(String[] args) {
		
		  AlbumInfo albuminfo = AlbumInfoService.findByAlbumAddr("http://www.56.com/w78/album-aid-212065.html");		
		  
          Element rootElement = new Element("albuminfo");
          Document myDocument = new Document(rootElement);
          
          rootElement.addContent(new Element("albumId").setText(Integer.toString(albuminfo.getAlbumId())));
         // rootElement.setAttribute("albumId",Integer.toString(albuminfo.getAlbumId()));  // 设置根结点属性
          rootElement.addContent(new Element("userId").setText(Integer.toString(albuminfo.getUserId())));
          rootElement.addContent(new Element("albumTitle").setText(albuminfo.getAlbumTitle()));
          rootElement.addContent(new Element("albumIntro").setText(albuminfo.getAlbumIntro()));
          rootElement.addContent(new Element("albumAddr").setText(albuminfo.getAlbumAddr()));
          rootElement.addContent(new Element("videoNub").setText(Integer.toString(albuminfo.getVideoNub())));
          rootElement.addContent(new Element("createTime").setText(new MySuperDate(albuminfo.getCreateTime()).getDateTimeString()));
          rootElement.addContent(new Element("imageUrl").setText(albuminfo.getImageUrl()));
          rootElement.addContent(new Element("flashUrl").setText(albuminfo.getFlashUrl()));
          rootElement.addContent(new Element("albumTypeId").setText(Integer.toString(albuminfo.getAlbumTypeId())));        
          
          XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat().setEncoding("utf-8"));
          OutputStream os = null;
          
              try {
				os = new FileOutputStream("D:\\javawork\\album\\albuminfo.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 + -