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