반응형
목적
DomParser 을 이용하여 xml파일을 읽어본다.
샘플 예제
package net.idmakeh.main;
import java.io.FileInputStream;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
public class SaxTest {
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder d=dbf.newDocumentBuilder();
String fNm=ClassLoader.getSystemResource("rule.xml").getPath();
System.out.println(fNm);
FileInputStream fio=new FileInputStream(fNm);
System.out.println(fio);
Document doc=d.parse(fio);
doc.normalize();
System.out.println(doc.getDocumentElement().getNodeName());
}
}
DomParser 을 이용하여 xml파일을 읽어본다.
샘플 예제
package net.idmakeh.main;
import java.io.FileInputStream;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
public class SaxTest {
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder d=dbf.newDocumentBuilder();
String fNm=ClassLoader.getSystemResource("rule.xml").getPath();
System.out.println(fNm);
FileInputStream fio=new FileInputStream(fNm);
System.out.println(fio);
Document doc=d.parse(fio);
doc.normalize();
System.out.println(doc.getDocumentElement().getNodeName());
}
}