IBM®
跳转到主要内容
    中国 [选择]    使用条款
 
 
Select a scope: Search for:    
    首页    产品    服务与解决方案     支持与下载    个性化服务    
跳转到主要内容

developerWorks 中国  >  XML  >

Make the most of Xerces-C++, Part 1

A parsing how-to for C++ programmers

developerWorks

Return to article.


Listing 5. SAX parser boilerplate (sans handlers)
        // GraphMain.cpp
#include <xercesc/sax2/SAX2XMLReader.hpp>
#include <xercesc/sax2/XMLReaderFactory.hpp>
#include <xercesc/sax2/ContentHandler.hpp>
#include <xercesc/sax2/DefaultHandler.hpp>
#include <xercesc/sax2/Attributes.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/framework/LocalFileInputSource.hpp>
#include <stdio.h>
#ifdef WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
#include "GraphHandler.h"
#include "XercesString.h"
#ifdef XERCES_CPP_NAMESPACE_USE
XERCES_CPP_NAMESPACE_USE
#endif
int main(int argc, char* argv[])
{
  if (argc < 2) return -1;
  // initialize the XML library
  XMLPlatformUtils::Initialize();
  if ( !access(argv[1], 04) )
  {
    printf("Cheesey Bar Graph!\n");
	XercesString wstrPath(argv[1]);
    SAX2XMLReader* pParser = XMLReaderFactory::createXMLReader();
    LocalFileInputSource source(wstrPath);
	// our application specific handler.
    GraphHandler handler;
    pParser->setFeature( XercesString("http://xml.org/sax/features/validation"), true );
    pParser->setFeature( XercesString("http://apache.org/xml/features/validation/dynamic"), true );
    pParser->setContentHandler(&handler);
    pParser->setErrorHandler(&handler);
    pParser->parse(source);
  }
  // terminate the XML library
  XMLPlatformUtils::Terminate();
  getchar();
  return 0;
}
      

Return to article.

    关于 IBM 隐私条约 联系 IBM 使用条款