티스토리 뷰

카테고리 없음

자바 xml 파싱 샘플

xemaker 2022. 8. 23. 18:00


자바 xml 파싱 샘플을 심플하게 살펴본다.

null이 찍혀서 null 인지 알았는데 데이터가 있는것이고

xml이 스트링이면 스트링 그대로 넣으면 안되고 inputsource stringreader를 사용해야 한다.

String xml="<aa>bb</aa>";

DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance();

DocumentBuilder docBuilder=documentFactory.newDocumentBuilder();

Document wdoc=docBuilder.parse( new InputStream(new StringReader(xml)) );

//System.out.println(wdoc); 해보면 [#document: null] 로 표시된다. 그래서 null 인줄 알았는데 데이터가 있다.

for(int i=0;i<list.getLength(); i++){
  String nodeValue=list.item(i).getTextContent();
  System.out.println(nodeValue);  
  }
 }
}


  

이러면 bb가 찍힌다.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2026/01   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함