ITeye博客

我眼中的w3c

fcxx182 · 2010-08-08 21:15 · 非技术 · Apache · XML · SUN · Markdown

package w3c;

import java.io.File; import java.io.IOException;

import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.SAXException;

import com.sun.org.apache.xerces.internal.parsers.DOMParser;

public class ParseXmlWithW3c {

/**
 * @param args
 */
public static void main(String[] args) 
{
	File file = new File("E:\\projectdevelop\\example\\example\\src\\w3c\\actionOperation.xml");
	DOMParser parser = new DOMParser();
	try {
		parser.parse("E:\\projectdevelop\\example\\example\\src\\w3c\\actionOperation.xml");
	} catch (SAXException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	Document doc = parser.getDocument();
	
	Element rootEle = doc.getDocumentElement();
	
	NodeList nodeList = rootEle.getElementsByTagName("operation");
	
	for (int i = 0; i<nodeList.getLength();i++)
	{
		Element operationEle = (Element)nodeList.item(i);
		
		NodeList actionChileEle = operationEle.getElementsByTagName("action_type");
		
		String actionType = (null == actionChileEle.item(0).getFirstChild()) ? "" : actionChileEle.item(0).getFirstChild().getNodeValue().trim();
		
		System.out.println("action_type" + i + " = " + actionType);
		
		NodeList operChileEle = operationEle.getElementsByTagName("operation_type");
		
		String operationType = (null == operChileEle.item(0).getFirstChild()) ? "" : operChileEle.item(0).getFirstChild().getNodeValue().trim();
		
		System.out.println("operation_type" + i + " = " + operationType);
		
		NodeList isCopyChileEle = operationEle.getElementsByTagName("is_copy");
		
		String coypType = (null == isCopyChileEle.item(0).getFirstChild()) ? "" : isCopyChileEle.item(0).getFirstChild().getNodeValue().trim();
		
		System.out.println("coypType" + i + " = " + coypType);
		
	}

}

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。