Skip to main content

XMLCPP Library 0.91

오랫만에 포스팅이네요. 요새 XMLCPP 만드는 재미에 빠져서요. :-)

XMLCPP 0.91 버전을 release했습니다. 0.9버전의 코드와 디렉토리들을 좀 정리한 내용도 있지만 가장 큰 변화는 Serializer 클래스가 구현되었다는 점입니다. PullParser가 XML을 읽기 위한 인터페이스라면 Serializer는 XML을 쓰기 위한 인터페이스입니다.

간단한 예로 다음 XML 파일을 만들어 보기로 하죠.




<br/> XMLCPP Library 0.91<br/>

blah blah




먼저 Serializer instance를 생성하고 원하는 feature를 activate한 후 output target을 지정합니다. 여기서는 "filename.xml"이라는 파일에 쓰기로 하겠습니다.


ofstream fs("filename.xml");

Serializer sr;
sr.set_feature(Serializer::LINE_SEPARATOR);
sr.set_feature(Serializer::INDENTATION);
sr.set_output("UTF-8", fs);


만약 LINE_SEPARATOR feature를 사용하지 않는다면 XML 전체 출력이 한줄로 됩니다. 물론 ignorable_whitespace() 함수를 사용하여 직접 줄바꿈이나 들여쓰기를 할 수도 있습니다.

Serializer instance가 준비되었으므로 이제 쓰면 됩니다. ;-) start_tag(), end_tag() 함수의 첫번째 인자는 namespace를 나타내는데 이 예제에서는 사용하지 않으므로 모두 null string을 사용하였습니다.


sr.start_document(L"UTF-8", L"");

sr.start_tag(L"", L"post");

sr.start_tag(L"", L"title");
sr.text(L"XMLCPP Library 0.91");
sr.end_tag(L"", L"title");

sr.start_tag(L"", L"content");
sr.text(L"blah blah");
sr.end_tag(L"", L"content");

sr.end_tag(L"", L"post");

sr.end_document();


마지막으로 열었던 fstream을 닫아주면 완료입니다.


fs.close();


물론 namespace와 attribute도 지원합니다. 자세한 내용은 Tutorial을 참고하시면 됩니다.

그리고 0.91 release하면서 프로젝트 홈페이지도 새단장했습니다. :-) sf.net에서 제공하는 Web service가 너무 느려서 결국 ideathinking.com에 한 구석을 차지하게 되었네요.

다음 계획은 libconv 없이 사용할 수 있도록 code converter를 구현하는 것입니다. 이 code converter는 UTF-8과 UTF-16만 지원할 예정입니다. libconv가 GNU license라 이 license를 사용할 수 없는 프로젝트에서도 사용할 수 있게 하기 위한 작업입니다.

이 작업이 끝나고 나서 Windows로 포팅할 예정입니다.

Comments

Popular posts from this blog

CodeHighlighter plugin test page.

This post is for testing CodeHighlighter plugin which uses GeSHi as a fontifier engine. ((Those code blocks are acquired from Google Code Search .)) ((For more supported languages, go CodeHighlighter plugin or GeSHi homepage.)) C++ (<pre lang="cpp" lineno="1">) class nsScannerBufferList { public: /** * Buffer objects are directly followed by a data segment. The start * of the data segment is determined by increment the |this| pointer * by 1 unit. */ class Buffer : public PRCList { public: Buffer() { ++index_; } PHP (<pre lang="php" lineno="4">) for ($i = 0; $i $value = ord( $utf8_string[ $i ] ); if ( $value < 128 ) { // ASCII $unicode .= chr($value); } else { if ( count( $values ) == 0 ) { $num_octets = ( $value } $values[] = $value; Lisp (<pre lang="lisp">) ;;; Assignment (define-caller-pattern setq ((:star var fo...

Textiler plugin test page

This post is for testing Textiler plugin . This plugin uses Textile engine (version 2.0.0). The sample text is come from Textile test page. (Note that the result will be vary according to your CSS options.) Supported wiki syntax Rendering result h2{color:green}. This is a title h3. This is a subhead p{color:red}. This is some text of dubious character. Isn't the use of "quotes" just lazy writing -- and theft of 'intellectual property' besides? I think the time has come to see a block quote. bq[fr]. This is a block quote. I'll admit it's not the most exciting block quote ever devised. Simple list: #{color:blue} one # two # three Multi-level list: # one ## aye ## bee ## see # two ## x ## y # three Mixed list: * Point one * Point two ## Step 1 ## Step 2 ## Step 3 * Point three ** Sub point 1 ** Sub point 2 Well, that went well. How about we insert an <a href="/" title="watch out">old-fashioned hypertext link</a>? Will the quo...

BookCover plugin test page

This post is for testing BookCover plugin . (( The previous test page has some comments from users.)) The 'Books Reading' section in the sidebar is also using this plugin. [ bookcover:1932394613] [bookcover:1932394613] [ bookcover:1590598385(Smart and Gets Things Done)] [bookcover:1590598385(Smart and Gets Things Done)] [ bookcover:1591841380(Wikinomics : How Mass Collaboration Changes Everything)] [bookcover:1591841380(Wikinomics : How Mass Collaboration Changes Everything)] [ bookcover:8995856408] [bookcover:8995856408] [ bookcover:8831793721] [bookcover:8831793721] [ bookcover:9788831793728] [bookcover:9788831793728]