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

Post on 13-Dec-2015

250 Views

Category:

Documents

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

99 주 실습강의주 실습강의XML Visualization(1)XML Visualization(1)

2009. 1 학기 , 소프트웨어 설계 및 실험 (Ⅰ)

Artificial Intelligence Laboratory

실습목표

Artificial Intelligence Laboratory

프로그램에서 XML 문서 이용 방법

DOM- Document Object Model- XML 문서를 Object의 개념으로 생각- 문서를 한번에 읽어서 처리 ( 수정 , 삭제 용이 )

SAX- Simple API for XML- 이벤트 중심의 방법- 문서를 순차적으로 읽음 ( 속도 , 메모리 측면에서 효율적 )- 문서 전체 구조정보를 가지지 않음

Artificial Intelligence Laboratory

XML DOM (Document Object Model)

Artificial Intelligence Laboratory

XML SAX(Simple API for XML)

Artificial Intelligence Laboratory

DOM VS SAX

Artificial Intelligence Laboratory

XML Parser

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

Artificial Intelligence Laboratory

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 생성

Artificial Intelligence Laboratory

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 추가

Artificial Intelligence Laboratory

Xerces 사용법

실행 테스트#include <xercesc/sax2/SAX2XMLReader.hpp>#include <xercesc/sax2/XMLReaderFactory.hpp>

int main(int argc, char * argv){return 0;

}

Artificial Intelligence Laboratory

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

Artificial Intelligence Laboratory

Artificial Intelligence Laboratory

DefaultHandler- Handler Class의 기본 모델

- SAX Parser를 사용하기 위한 base class- DefaultHandler Class 를 상속하여 Interface함수를

재정의 하여 사용

Artificial Intelligence Laboratory

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)

Artificial Intelligence Laboratory

startDocument()함수 추가- 클래스 뷰 -> HanderClass 우클릭 -> 추가 -> 함수 추가

반환 형식 void 함수 이름 startDocument() 마침

- endDocument() 함수 추가

각각 문서의 시작과 끝에 자동으로 호출됨 .

Artificial Intelligence Laboratory

Main 작성

Artificial Intelligence Laboratory

Main

Artificial Intelligence Laboratory

추가구현

<book genre="novel"><title>The Confidence Man</title>

</book>

OutputElementStart=bookAttributeQName=genreAttributeValue=novelElementStart=titleTextValue=The Confidence ManElementEnd=titleElementEnd=book

Artificial Intelligence Laboratory

추가구현

Element - XMLString::transcode(qname)

qname의 값 출력 . Attribute

- attribute.getLength()

Attribute 개수 .- attribute.getQName(index)

Attribute QName- attribute.getValue(index)

Attribute Value

top related