---
title: "我眼中的w3c"
author: "fcxx182"
date: "2010-08-08T21:15:57Z"
tags: ["Apache", "SUN", "XML"]
categories: ["非技术"]
slug: "w3c"
draft: false
lastmod: "2010-08-08T21:15:57Z"
id: 732241
url: "https://fcxx182.iteye.com/blog/732241"
---

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);
			
		}

	}

}
