Today`s Famaous quotes here : Successful people often change their methods instead of goals.
XML parser :
1.DOM,SAX,JDOM,DOM4J.
The First DOM (Document Object Model) ,Lets Start:
XML parser :
1.DOM,SAX,JDOM,DOM4J.
The First DOM (Document Object Model) ,Lets Start:
JavaCode :
package test;
import java.io.File;
import org.w3c.dom.*;
import javax.xml.parsers.*;
public class DOMReader{
public static void main(String[] args) {
try{
//This file name
File file = new File("pathName");
//get the factory of bulider
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
//Create bulider
DocumentBuilder builder = factory.newDocumentBuilder();
//start parse this file
Document document = (Document) builder.parse(file);
//Obtained by name
NodeList nl = document.getElementsByTagName("VALUE");
//There are many Byte and data so have to for
for(int i =0;i<nl.getLength();i++){
System.out.println("Massage one" + document.getElementsByTagName("NO").item(i)
.getFirstChild().getNodeValue());
}
}catch(Exception e){
e.printStackTrace();
}
}
}
2.Attributes : Document, Element,node, nodeList,attribute ,comment these are sex Attributes about DOM parser.
3.Level : NO.1 DOM , NO.2 DOM , NO.3 DOM these are about time.
4.Methods : getElementById(); & getElementByTagName();
5.Attributes :parentNode、firstChild and lastChild.
Note :1. DOM(Document Object Model ) will waste memory . So i support use SAX or other parser.
Iparhan_Java 2016-6-23 GoodLuck!