JAVA&스프링/JAVA&JSP공부

java : xml 파싱하기

멋진꿈 2011. 10. 24. 17:18

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

DocumentBuilder db = dbf.newDocumentBuilder();
 String observationXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+new String(result.getIncomingResult()).trim();

Document doc = db.parse(new InputSource(new java.io.StringReader(observationXml)));

doc.getDocumentElement().normalize();

Element root = doc.getDocumentElement();
       
NodeList omObservation = root.getElementsByTagName("태그이름");

Node nodeOmObservation = omObservation.item(omObservationCnt);
Element elementOmObservation = (Element)nodeOmObservation;