亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? xmlutil.java

?? 使用dom4j實(shí)現(xiàn)xml文件的操作
?? JAVA
字號(hào):

/**
 * dom4j mode
 * by hjs
 * 2007.7.16
 */

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;

public class XmlUtil {
    @SuppressWarnings("unused")
	private static Log log = LogFactory.getLog(XmlUtil.class);    

	/**
	 * create a empyt xml document object
	 * @param xmlPath
	 * @return
	 */
	public static Document createEmptyXmlFile(String xmlPath){
		if(xmlPath==null || xmlPath.equals(""))
			return null;

		XMLWriter output;
		Document document = DocumentHelper.createDocument();
		    
		OutputFormat format = OutputFormat.createPrettyPrint();
		try {
			output = new XMLWriter(new FileWriter(xmlPath), format);
			output.write(document);
			output.close();
		} catch (IOException e) {
			return null;
		}
		return document;
	}

	public static Document createEmptyXmlFile(String xmlPath, String rootStr){
		if(xmlPath==null || xmlPath.equals(""))
			return null;
		
		XMLWriter output;
		Document document = DocumentHelper.createDocument();
		if(document!=null && rootStr!=null && !rootStr.trim().equals("")){
			document.addElement(rootStr);
		}
		    
		OutputFormat format = OutputFormat.createPrettyPrint();
		try {
			output = new XMLWriter(new FileWriter(xmlPath), format);
			output.write(document);
			output.close();
		} catch (IOException e) {
			return null;
		}
		return document;
	}

	public static Document createDC(){
		Document document = DocumentHelper.createDocument();
		return document;
	}

	/**
	 * output document into xml file
	 */
	public static boolean saveXmlFile(Document document, String xmlPath){
		if(document==null)
			return false;
		
		if(xmlPath==null || xmlPath.equals(""))
			return false;
		
	    File file = new File(xmlPath);
	    File dir = file.getParentFile();
	    if(dir!=null && !dir.exists()){
	    	dir.mkdirs();
	    }
	    
		XMLWriter output;
		
		OutputFormat format = OutputFormat.createPrettyPrint();
		try {
			output = new XMLWriter(new FileWriter(xmlPath), format);
			output.write(document);
			output.close();
		} catch (IOException e) {
			return false;
		}
		return true;
	}

	public static boolean saveXmlFile(Document document, String xmlPath, String coding){
		if(document==null)
			return false;
		
		if(xmlPath==null || xmlPath.equals(""))
			return false;
		
	    File file = new File(xmlPath);
	    File dir = file.getParentFile();
	    if(dir!=null && !dir.exists()){
	    	dir.mkdirs();
	    }
	    
		XMLWriter output;
		
		OutputFormat format = OutputFormat.createPrettyPrint();
		format.setEncoding(coding);
		try {
			output = new XMLWriter(new FileWriter(xmlPath), format);
			output.write(document);
			output.close();
		} catch (IOException e) {
			return false;
		}
		return true;
	}
	
	/**
	 * get DC from xml file
	 * @param xmlPath
	 * @return
	 * @throws DocumentException
	 */
	public static Document getDC(String xmlPath){
		if(xmlPath==null || xmlPath.equals(""))
			return null;

		File file = new File(xmlPath);
		if(file.exists()==false){
			return createEmptyXmlFile(xmlPath);
		}
		
		SAXReader reader = new SAXReader();
		Document document = null;
		try {
			document = reader.read(xmlPath);
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return document;
	}

	public static Document getDC(String xmlPath, String rootStr){
		if(xmlPath==null || xmlPath.equals(""))
			return null;

		File file = new File(xmlPath);
		if(file.exists()==false){
			return createEmptyXmlFile(xmlPath, rootStr);
		}
		
		SAXReader reader = new SAXReader();
		Document document = null;
		try {
			document = reader.read(xmlPath);
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return document;
	}

	/**
	 * get DC from xml String
	 */
	public static Document getDCFromString(String xmlStr){
		Document document = null;
		try {
			document = DocumentHelper.parseText(xmlStr);
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return document;
	}
	
	/**
	 * get root node from DC
	 * @param document
	 * @return
	 */
	public static Element getRootNode(Document document){
		if(document==null)
			return null;
		
		Element root = document.getRootElement();
		return root;
	}

	/**
	 * add root node into DC
	 * @param document
	 * @param nodeName
	 * @param attrName
	 * @param attrVal
	 * @param content
	 * @return
	 */
	public static Element addRootNode(Document document, String nodeName, 
			String attrName, String attrVal, String content){
		if(document==null)
			return null;
		
		if(nodeName==null || nodeName.trim().equals("")){
			return null;
		}
		
		Element e = document.addElement(nodeName);
		
		if(attrName!=null && !attrName.trim().equals("")
				&& attrVal!=null && !attrVal.trim().equals("")){
			e.addAttribute(attrName, attrVal);
		}
		
		if(content!=null && !content.trim().equals("")){
			e.addText(content);
		}

		return e;
	}

	public static Element addRootNode(Document document, String nodeName, 
			String attrName, String attrVal){
		if(document==null)
			return null;
		
		if(nodeName==null || nodeName.trim().equals("")){
			return null;
		}
		
		Element e = document.addElement(nodeName);
		
		if(attrName!=null && !attrName.trim().equals("")
				&& attrVal!=null && !attrVal.trim().equals("")){
			e.addAttribute(attrName, attrVal);
		}

		return e;
	}

	public static Element addRootNode(Document document, String nodeName, 
			String content){
		if(document==null)
			return null;
		
		if(nodeName==null || nodeName.trim().equals("")){
			return null;
		}
		
		Element e = document.addElement(nodeName);
		
		if(content!=null && !content.trim().equals("")){
			e.addText(content);
		}

		return e;
	}

	public static Element addRootNode(Document document, String nodeName){
		if(document==null)
			return null;
		
		if(nodeName==null || nodeName.trim().equals("")){
			return null;
		}
		
		Element e = document.addElement(nodeName);

		return e;
	}

	/**
	 * append a child node to a parent node 
	 * @param parent
	 * @param nodeName
	 * @param attrName
	 * @param attrVal
	 * @return
	 */
	public static Element addNode(Element parent, String nodeName, 
			String attrName, String attrVal, String content){
		if(parent==null)
			return null;
		
		if(nodeName==null || nodeName.trim().equals("")){
			return null;
		}
		
		Element e = parent.addElement(nodeName);
		
		if(attrName!=null && !attrName.trim().equals("")
				&& attrVal!=null && !attrVal.trim().equals("")){
			e.addAttribute(attrName, attrVal);
		}
		
		if(content!=null && !content.trim().equals("")){
			e.addText(content);
		}

		return e;
	}

	public static Element addNode(Element parent, String nodeName, 
			String attrName, String attrVal){
		if(parent==null)
			return null;
		
		if(nodeName==null || nodeName.trim().equals("")){
			return null;
		}
		
		Element e = parent.addElement(nodeName);
		
		if(attrName!=null && !attrName.trim().equals("")
				&& attrVal!=null && !attrVal.trim().equals("")){
			e.addAttribute(attrName, attrVal);
		}

		return e;
	}
	
	public static Element addNode(Element parent, String nodeName, 
			String content){
		if(parent==null)
			return null;
		
		if(nodeName==null || nodeName.trim().equals("")){
			return null;
		}
		
		Element e = parent.addElement(nodeName);
		
		if(content!=null && !content.trim().equals("")){
			e.addText(content);
		}

		return e;
	}
	
	/**
	 * get child of a node
	 * @param parent
	 * @param nodeName
	 * @return
	 */
	public static Element getChild(Element parent, String nodeName){
		if(parent==null)
			return null;
		
		if(nodeName==null || nodeName.trim().equals(""))
			return null;
		
		Element e = null;
		Iterator it = getChildren(parent);
		while(it!=null && it.hasNext()){
			Element k = (Element)it.next();
			if(k==null)continue;
			if(k.getName().equalsIgnoreCase(nodeName)){
				e = k;
				break;
			}
		}
			
		return e;
	}

	/**
	 * @param parent
	 * @param nodeName
	 * @return
	 */
	public static Element getChild(Element parent, String nodeName, String nodeVal){
		if(parent==null)
			return null;
		
		if(nodeName==null || nodeName.trim().equals(""))
			return null;
		
		Element e = null;
		Iterator it = getChildren(parent);
		while(it!=null && it.hasNext()){
			Element k = (Element)it.next();
			if(k==null)continue;
			if(k.getName().equalsIgnoreCase(nodeName) && k.getText().equalsIgnoreCase(nodeVal)){
				e = k;
				break;
			}
		}
			
		return e;
	}
	
	/**
	 * select node from a DC var string "/xx/xx/xx/" etc.
	 * @param document
	 * @param path
	 * @return
	 */
	public static Element select(Document document, String path){
		Element e = null, curr = null;
		
		if(document==null)
			return null;
		
		if(path==null || path.trim().equals(""))
			return null;
		
		String[] tags = path.split("/");
		if(tags==null)
			return null;
		
		int i = 0, j = 0;
		List<String> list = new ArrayList<String>();
		for(i=0;i<tags.length;i++){
			String t = tags[i];
			if(t==null || t.trim().equals(""))
				continue;
			list.add(t);
		}
		
		for(i=0;i<list.size();i++){
			String t = list.get(i);
			if(j==0){
				curr = getRootNode(document);
				if(curr!=null && !curr.getName().equals(t))
					break;
			}
			else{
				curr = getChild(curr,t);
				if(curr==null)
					break;
			}
			j++;
		}
		
		if(j==list.size())
			e = curr;
		
		return e;
	}

	public static void delete(Element parent,int idx){
		if(parent==null)return;
		parent.elements().remove(idx);
	}

	public static void delete(Element parent, String nodeName){
		Element e = getChild(parent,nodeName);
		if(e!=null)
			parent.remove(e);
	}

	public static void delete(Element parent, String nodeName, String nodeVal){
		Element e = getChild(parent,nodeName,nodeVal);
		if(e!=null)
			parent.remove(e);
	}
	
	/**
	 * get kids of a node
	 * @param node
	 * @return
	 */
	public static List getKids(Element node){
		if(node==null)
			return null;

		return node.elements();
	}

	public static Iterator getChildren(Element node){
		if(node==null)
			return null;
		
		Iterator it = node.elementIterator();
		return it;
	}

	public static List<Element> getChildList(Element node){
		if(node==null)
			return null;
		
		Iterator it = node.elementIterator();
		if(it==null)
			return null;
		
		List<Element> kids = new ArrayList<Element>();
		while(it.hasNext()){
			Element e = (Element)it.next();
			if(e!=null)
				kids.add(e);
		}
		return kids;
	}

	/**
	 * travell
	 * @param mode 
	 * 		0: order by floor
	 * 		1: root first
	 */
	public static List<Element> travell(Document document, int mode){
		Element root = getRootNode(document);
		if(root==null)
			return null;
		
		if(mode<=0)
			mode = 0;
		
		List<Element> nodeList = new ArrayList<Element>();
		List<Element> resultList = new ArrayList<Element>();
		nodeList.add(root);
		visit(nodeList,resultList,mode);
		
		return resultList;
	}
	
	private static void visit(List<Element> stack, List<Element> result, int mode){
		if(stack.size()<=0)
			return;
		
		Element e = (Element)stack.get(0);
		if(e==null)
			return;
		
		result.add(e);
		stack.remove(0);
		Iterator it = getChildren(e);
		if(mode==0){
			while(it.hasNext()){
				Element k = (Element)it.next();
				stack.add(k);
			}
			visit(stack,result, mode);
		}
		if(mode==1){
			while(it.hasNext()){
				Element k = (Element)it.next();
				stack.add(k);
				visit(stack,result, mode);
			}
		}
	}
	
	public static void main(String args[]){
		/*
		String strImg = "<root><a href='http://www.xiaoshuo.com/jsp/writers.jsp'><img src='http://www.xiaoshuo.com/timages/zzzl.gif' border='0' /></a><a href='/jsp/club/index.jsp?clubid=200242'><img src='/timages/images_column/xqhyyh.gif' border='0' /></a><a href='http://www.xiaoshuo.com/jsp/xianren.jsp'><img src='http://www.xiaoshuo.com/timages/xianren.gif' border='0' /></a></root>";
		Document dc = getDCFromString(strImg);
		Element root = dc.getRootElement();
		List<Element> list = getChildList(root);
		for(int i=0;list!=null && i<list.size();i++){
			Element e = (Element)list.get(i);
			log.info(e.attribute("href").getValue());
			List sub = getChildList(e);
			if(sub==null)continue;
			e = (Element)sub.get(0);
			log.info(e.attribute("src").getValue());
		}
		*/
		String xmlFile = "c:/test.xml";
		
		//List<Element> wList = null;
		Document dc = XmlUtil.getDC(xmlFile);
		Element w = XmlUtil.select(dc,"/root/article/");
		if(w==null){
			Element r = XmlUtil.getRootNode(dc);
			if(r==null)r = XmlUtil.addRootNode(dc, "root");
			if(r!=null)w = XmlUtil.addNode(r, "article", "");
		}
		if(w!=null){
			XmlUtil.addNode(w, "link", "test.jpg");
		}
		if(w!=null){
			List list = XmlUtil.getKids(w);
			for(int i=0;i<list.size();i++){
				Element e = (Element)list.get(i);
				log.info(e.asXML());
			}
		}
		//wList = XmlUtil.getChildList(w);
		XmlUtil.saveXmlFile(dc, xmlFile);
	}
}

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美三级日韩三级| 色综合天天天天做夜夜夜夜做| 欧美激情中文不卡| 欧美大片在线观看一区| 一本久久综合亚洲鲁鲁五月天| 免费不卡在线观看| 国产欧美久久久精品影院| 欧美日韩一区二区不卡| 91麻豆国产精品久久| 国产成人av影院| 国产精品自在欧美一区| 精品一区二区三区在线播放| 日韩电影在线免费| 三级影片在线观看欧美日韩一区二区 | 欧美日韩在线直播| 欧美在线观看一区| 欧美日韩国产综合一区二区 | 亚洲成人一区在线| 亚洲va韩国va欧美va精品 | gogogo免费视频观看亚洲一| 国产精品久久夜| 国产精品午夜免费| 亚洲天堂成人网| 亚洲超丰满肉感bbw| 蜜臀a∨国产成人精品| 国产精品一区久久久久| 成人午夜激情影院| 欧美最新大片在线看| 91精品国产综合久久香蕉麻豆 | 欧美日韩国产小视频在线观看| 欧美日本在线播放| 久久久高清一区二区三区| 中文字幕五月欧美| 亚洲国产成人高清精品| 国精品**一区二区三区在线蜜桃 | 国产成人久久精品77777最新版本 国产成人鲁色资源国产91色综 | 亚洲国产成人tv| 九九精品一区二区| 不卡视频在线观看| 在线不卡中文字幕| 中文字幕欧美一| 极品少妇xxxx偷拍精品少妇| 色www精品视频在线观看| 日韩欧美在线1卡| 亚洲人成人一区二区在线观看| 久久精品国产久精国产| 91国模大尺度私拍在线视频| 久久久精品免费网站| 亚洲福中文字幕伊人影院| 日韩高清在线观看| 成人av资源在线| 91精品在线观看入口| 久久精品亚洲国产奇米99| 亚洲欧美日韩久久精品| 久久99久久精品欧美| 欧美日韩成人在线一区| 国产精品免费av| 麻豆极品一区二区三区| 色综合天天做天天爱| 久久蜜臀精品av| 亚洲成a人片综合在线| av网站免费线看精品| 精品国产一区二区在线观看| 一区二区三区av电影| 成人综合在线网站| 欧美成人一区二区| 美女高潮久久久| 91 com成人网| 亚洲一区自拍偷拍| 欧美在线观看视频在线| 国产精品蜜臀在线观看| 成人妖精视频yjsp地址| 欧美成人a∨高清免费观看| 日韩高清不卡一区二区| 91精品国产一区二区人妖| 亚洲亚洲精品在线观看| 在线免费一区三区| 一区二区三区在线观看视频 | 成人免费黄色大片| 国产精品私房写真福利视频| 成人白浆超碰人人人人| ...xxx性欧美| 色综合婷婷久久| 亚洲综合色区另类av| 欧美午夜电影一区| 视频在线观看91| 日韩午夜在线播放| 成人免费视频国产在线观看| 国产蜜臀av在线一区二区三区| 国产黄色精品网站| 亚洲欧美日韩系列| 欧美不卡在线视频| 成人激情av网| 亚洲成人高清在线| 久久久精品国产99久久精品芒果| 国产福利一区二区三区| 成人免费在线视频观看| 欧美午夜不卡在线观看免费| 另类成人小视频在线| 国产欧美日韩精品在线| 欧美综合久久久| 国产在线视视频有精品| 亚洲欧美电影一区二区| 欧美变态tickle挠乳网站| 色偷偷一区二区三区| 国产河南妇女毛片精品久久久 | 喷白浆一区二区| 亚洲天堂2016| 欧美国产日本视频| 亚洲精品一区二区三区蜜桃下载| 欧美日韩三级在线| 欧美日韩高清影院| 欧美三级中文字幕| 色婷婷久久一区二区三区麻豆| 国产成人综合视频| 国产91精品露脸国语对白| 国产精品一二三四区| 久久精品999| 久久成人久久爱| 国产精品资源网站| 东方欧美亚洲色图在线| 成人天堂资源www在线| av成人免费在线观看| 久久综合狠狠综合久久综合88| 欧美放荡的少妇| 精品国产欧美一区二区| 国产人成亚洲第一网站在线播放| 国产欧美一区二区三区网站| 国产精品蜜臀在线观看| 亚洲综合在线五月| 免费久久精品视频| 成a人片国产精品| 欧美日韩成人激情| 精品国产99国产精品| 国产精品美女久久久久久2018| 亚洲精品成人a在线观看| 青青草国产精品97视觉盛宴| 懂色av一区二区三区蜜臀| 在线亚洲高清视频| 精品久久久网站| 国产成人高清在线| 91精品福利在线| 日韩欧美在线123| 亚洲视频一区在线| 国产福利91精品一区二区三区| 99这里只有久久精品视频| 91精品国产一区二区三区香蕉| 亚洲国产精品激情在线观看| 丝袜亚洲另类丝袜在线| 91视视频在线观看入口直接观看www | 久久久久久久久一| 亚洲成人自拍偷拍| 波多野结衣一区二区三区| 欧美大片顶级少妇| 日韩专区中文字幕一区二区| aaa国产一区| 国产精品久久久久久久久免费相片 | 黑人巨大精品欧美黑白配亚洲 | 欧美高清视频一二三区| 亚洲欧美激情一区二区| 成人中文字幕合集| 久久综合九色综合97婷婷| 午夜精品在线看| 91久久精品国产91性色tv| 日韩一区欧美小说| 91在线精品秘密一区二区| 久久久美女毛片| 国产精品一二二区| 久久夜色精品国产欧美乱极品| 蜜桃视频免费观看一区| 欧美电影在线免费观看| 天天色天天操综合| 欧美一区午夜视频在线观看| 天堂影院一区二区| 欧美精品久久一区二区三区| 五月婷婷色综合| 日韩欧美精品在线视频| 高清视频一区二区| 国产精品沙发午睡系列990531| 成人午夜精品在线| 一区二区高清免费观看影视大全| 欧美天堂亚洲电影院在线播放| 丝瓜av网站精品一区二区| 日韩视频一区在线观看| 丰满少妇在线播放bd日韩电影| 亚洲特级片在线| 在线91免费看| 国产激情视频一区二区三区欧美| 成人欧美一区二区三区黑人麻豆| 色综合久久久久综合体桃花网| 婷婷六月综合亚洲| 久久久久国色av免费看影院| 色狠狠色噜噜噜综合网| 国产一区二区视频在线| 一区二区三区在线影院| 精品对白一区国产伦| 色综合久久天天| 成人午夜视频免费看| 美女视频黄 久久| 亚洲免费av在线|