1 / 19

9 주 실습강의 XML Visualization(1)

9 주 실습강의 XML Visualization(1). 2009. 1 학기 , 소프트웨어 설계 및 실험 (Ⅰ). 실습목표. 프로그램에서 XML 문서 이용 방법. DOM Document Object Model XML 문서를 Object 의 개념으로 생각 문서를 한번에 읽어서 처리 ( 수정 , 삭제 용이 ) SAX Simple API for XML 이벤트 중심의 방법 문서를 순차적으로 읽음 ( 속도 , 메모리 측면에서 효율적 ) 문서 전체 구조정보를 가지지 않음.

fifi
Download Presentation

9 주 실습강의 XML Visualization(1)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 9주 실습강의XML Visualization(1) 2009. 1학기, 소프트웨어 설계 및 실험(Ⅰ)

  2. 실습목표

  3. 프로그램에서 XML 문서 이용 방법 • DOM • Document Object Model • XML 문서를 Object의 개념으로 생각 • 문서를 한번에 읽어서 처리(수정, 삭제 용이) • SAX • Simple API for XML • 이벤트 중심의 방법 • 문서를 순차적으로 읽음(속도, 메모리 측면에서 효율적) • 문서 전체 구조정보를 가지지 않음

  4. XML DOM (Document Object Model)

  5. XML SAX(Simple API for XML)

  6. DOM VS SAX

  7. XML Parser • Xerces • http://xerces.apache.org/xerces-c/ • 오픈 소스 XML 파서 • IBM에서 개발(xml4c) • C++, Java, Perl 지원 • 현재 Apache에서 개발/관리 • 현재 버전 Xerces-C++ 3.0.1

  8. Xerces 설치 • Xerces Download • http://xerces.apache.org/xerces-c/download.cgi • xerces-c-3.0.1.zip (for windows) • 압축해제 • 솔루션 실행 • ~\xerces-c-3.0.1\projects\Win32\VC9\xerces-all\Xerces-all.sin • Build (빌드 -> 솔루션빌드단축키 F6) • ~\xerces-c-3.0.1\Build\Win32\VC9\Debug\xerces-c_3_0D.dll 생성

  9. Xerces 사용법 • 새 프로젝트 생성( VC++ Win32 Console Application) • 추가 옵션에서 빈 프로젝트 체크 • 프로젝트에서 main.cpp 추가 • 프로젝트 속성 설정 • C/C++ -> 일반 -> 추가 포함 디렉터리 • ~\xerces-c-3.0.1\src 추가 • 링커 -> 일반 -> 추가 라이브러리 디렉터리 • ~\xerces-c-3.0.1\Build\Win32\VC9\Debug 추가 • ~\xerces-c-3.0.1\Build\Win32\VC9\Debug\xerces-c_3_0D.dll • 프로젝트 폴더에 복사 • 링커 -> 입력 -> 추가종속성 • Xerces-c_3D.lib 추가

  10. Xerces 사용법 • 실행 테스트 #include <xercesc/sax2/SAX2XMLReader.hpp> #include <xercesc/sax2/XMLReaderFactory.hpp> int main(int argc, char * argv){ return 0; }

  11. XML Handler 생성 • Handler Class 생성 • 클래스 뷰 -> 프로젝트 추가 -> 클래스 • C++ 클래스 • 클래스 이름 설정 (ex SAXHandler) • 기본클래스 DefaultHandler • “예” 클릭 • #include <xercesc/sax2/DefaultHandler.hpp> 추가 • DefaultHandler Interface • #include <xercesc/sax2/Attributes.hpp> 추가 • XECES_CPP_NAMESPACE_USE 추가 • namespace

  12. DefaultHandler • Handler Class의 기본 모델 • SAX Parser를 사용하기 위한 base class • DefaultHandler Class 를 상속하여 Interface함수를 재정의 하여 사용

  13. DefaultHandler의 주요 메서드 • http://xerces.apache.org/xerces-c/apiDocs-3/classDefaultHandler.html virture void startDocument() virture void endDocument() virture void startElement( const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs) virture void endElement( const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname) virture characters( const XMLCh *const chars, const XMLSize_t length)

  14. startDocument()함수 추가 • 클래스 뷰 -> HanderClass 우클릭 -> 추가 -> 함수 추가 • 반환 형식 void • 함수 이름 startDocument() • 마침 • endDocument() 함수 추가 • 각각 문서의 시작과 끝에 자동으로 호출됨.

  15. Main 작성

  16. Main

  17. 추가구현 <book genre="novel"> <title>The Confidence Man</title> </book> Output ElementStart=book AttributeQName=genre AttributeValue=novel ElementStart=title TextValue=The Confidence Man ElementEnd=title ElementEnd=book

  18. 추가구현 • Element • XMLString::transcode(qname) • qname의 값 출력. • Attribute • attribute.getLength() • Attribute 개수. • attribute.getQName(index) • AttributeQName • attribute.getValue(index) • Attribute Value

More Related