Compiling and vc6 instances in Apache xerces C ++ windows

Source: Internet
Author: User
I. This article describes how to use VC to call the Apache xerces C ++ interface on the Win32 platform or directly use this project in your project. The installation and call in Linux will be provided in the next step. II. Obtain the xerces C ++ software package. · If you only want to directly call the xerces C ++ package and do not want to compile it by yourself, you can get a Binary Package in listing one xerces-c_2_7_0-windows_2000-msvc_60.zip. If you want to compile the xerces C ++ package by yourself, you can get a Binary Package in listing two xerces-c-current.zip three. Add the xerces C ++ Binary Package to your project. After planting xerces-c_2_7_0-windows_2000-msvc_60.zip, we will start the following content: to complete this example, I will explain my folder path arrangement. Myxml ---- | ------ lib | ------ include | ------ bin | ------ myprojects I use the myxml folder to store everything we want to experiment. Lib is used to store the xerces C ++ lib File Include is used to store the xerces header file. Bin is used to store the intermediate code of your project and exe or DLL files. All your projects are in myprojects.
  1. Now we use VC to create a console application empty project of domtest in the myprojects folder.
  2. Decompress the xerces source ZIP file to a working directory. Put all the files in the // xerces-c-src_2_7_0 // lib folder into myxml/lib. Copy xercesc under the // xerces-c-src_2_7_0 // SRC folder to myxml/include and put the xerces-c-src_2_7_0 file under the // xerces-c_2_7D.dll // lib into myxml/bin.
  3. Create two files cxml. cpp and cxml. h In the domtest project. The code is later in this article.
  4. In this way, we are half done. All files are ready.
  5. Set domtest project-> Settings.
1). Set intermediate files to ../bin on the General Panel. Output files: ../bin. 2) on the C/C ++ panel, select Preprocessor for category and enter..././include in additional include directories. 3). Select input in category on the Link Panel, remove everything in the object/library modules, enter the kernel32.lib user32.lib xerces-c_2D.lib. Enter.../lib in additonal library path. 3) Other settings remain unchanged. After confirming, build your project. If you want to run your program, do not forget that there is a xerces-c_2_7D.dll file in the bin. In this way, you can easily use Apache xerces C ++ in your project. The above file path arrangement can be done according to your own setting preferences, if you need to understand the meaning of the three settings in VC, you can tell me what you don't understand. 4. the process of compiling xerces C ++ source code and adding it to your project is actually an additional process of self-compiling code, which is mentioned here because many people directly compile the code and encounter problems, there are also two ways to add xerces to your project. My suggestion is to use the method mentioned in the third point, because if you directly add the xerces project to your project, the compilation is slow. Okay.
  1. 1. After downloading xerces-c-current.zip, decompress the xerces ZIP file to a working directory. Xerces-C ++ has its own directory structure. Therefore, ensure that the relative path name is maintained in this step.
  2. Go to the // xerces-c-src_2_7_0/projects/Win32 // vc6 // xerces-All // folder with Windows Explorer or the File Manager you are using and click the xerces-all.dsw workspace file to start Microsoft developer studio.
    Note:These instructions assume that you compile Win32 applications in Visual Studio 6. For Visual Studio dot-net or win64 applications, repeat steps 1 and 2 in the respective directories of win64 or vc7.
  1. In developer studio, make xerceslib an active project and press F7 to compile the DLL. At this time, there may be three errors. In the project-> Settings-> link, the IA64 is changed to ix86, And/machine: IA64 is removed from C/C ++ in category: change the General Preprocessor definitions win64 to Win32 and then press F7 to compile the DLL.
  2. The generated file is found in the corresponding file name folder under the xerces-c-src_2_3_0. And use it according to the third big point above.
Note: If you compile above, there are two errors: F:/downloads/xerces-C-current/xerces-c-src_2_7_0/src/xercesc/util/platforms/Win32/win32platformutils. CPP (690): Error c2039: 'interlockedcompareexchangepointer ': is not a member of ''global namespace''
F:/downloads/xerces-C-current/xerces-c-src_2_7_0/src/xercesc/util/platforms/Win32/win32platformutils. cpp (690): Error c2065: 'interlockedcompareexchangepointer ': Undeclared identier
That is because Apache is a win64 platform by default in this project. Therefore, you only need to select the xerceslib project on the left of project-> setting, and then select general in the C ++ option on the right, after changing the first win64 of the next Preprocessor definitions to Win32, clean your xerceslib project and rebuild. You can find the DLL and Lib you want to use in the xerces-c-src_2_7_0/build/win64/vc6/release, code 1 // cxml. CPP # include <string> # include <iostream> # include <sstream> # include <stdexcept> # include <list> # include "cxml. H "cxml: cxml () {try {// initialize xerces-C ++ library xmlplatformutils: Initialize ();} catch (xercesc: xmlexception & excp) {char * MSG = xmlstring: transcode (excp. getmessage (); printf ("XML toolkit initialization er Ror: % s/n ", MSG); xmlstring: release (& MSG) ;}// create an xercesdomparser object for parsing the document m_domxmlparser = new xercesdomparser;} cxml ::~ Cxml () {try {xmlplatformutils: Terminate ();} catch (xmlexception & excp) {char * MSG = xmlstring: transcode (excp. getmessage (); printf ("XML toolkit terminate error: % s/n", MSG); xmlstring: release (& MSG) ;}} void cxml :: xmlparser (string & xmlfile) Throw (STD: runtime_error) {// get the file information status // configure domparser m_domxmlparser-> setvalidationscheme (xercesdomparser: val_auto ); m_domxmlparser-> setdonamespaces (Fa LSE); m_domxmlparser-> setdoschema (false); m_domxmlparser-> setloadexternaldtd (false); try {// call the parsing interface m_domxmlparser-> parse (xmlfile. c_str (); // get the DOM tree domdocument * xmldoc = m_domxmlparser-> getdocument (); domelement * proot = xmldoc-> getdocumentelement (); If (! Proot) {Throw (STD: runtime_error ("Empty XML document");} // create a walker to visit all text nodes. /*************************************** * ****** domtreewalker * Walker = xmldoc-> createtreewalker (proot, domnodefilter: show_text, null, true); // use the tree Walker to print out the text nodes. STD: cout <"treewalker:/N"; for (domnode * Current = Walker-> nextnode (); current! = 0; current = Walker-> nextnode () {char * strvalue = xmlstring: transcode (current-> getnodevalue (); STD: cout <strvalue; xmlstring:: release (& strvalue);} STD: cout <STD: Endl; **************************************** * ******* // create an iterator to visit all text nodes. domnodeiterator * iterator = xmldoc-> createnodeiterator (proot, domnodefilter: show_text, null, true); // use the tree wal Ker to print out the text nodes. STD: cout <"iterator:/N"; for (domnode * Current = iterator-> nextnode (); current! = 0; current = iterator-> nextnode () {string strvalue = xmlstring: transcode (current-> getnodevalue (); STD :: cout <strvalue <Endl;} STD: cout <STD: Endl;} catch (xercesc: xmlexception & excp) {char * MSG = xercesc: xmlstring:: transcode (excp. getmessage (); ostringstream errbuf; errbuf <"error parsing file:" <MSG <flush; xmlstring: release (& MSG );}} int main (INT argc, char * argv []) {if (Argc! = 2) {return 0;} string xmlfile = argv [1]; cxml. xmlparser (xmlfile); Return 0;} Code 2 // cxml. h # ifndef xml_parser_hpp # define xml_parser_hpp # include <xercesc/util/transservice. HPP> # include <xercesc/DOM/Dom. HPP> # include <xercesc/DOM/domdocument. HPP> # include <xercesc/DOM/domdocumenttype. HPP> # include <xercesc/DOM/domelement. HPP> # include <xercesc/DOM/domimplementation. HPP> # include <xercesc/DOM Implementationls. HPP> # include <xercesc/DOM/domnodeiterator. HPP> # include <xercesc/DOM/domnodelist. HPP> # include <xercesc/DOM/domtext. HPP> # include <xercesc/DOM/domattr. HPP> # include <xercesc/parsers/xercesdomparser. HPP> # include <xercesc/util/xmluni. HPP> # include <xercesc/framework/xmlformatter. HPP> # include <xercesc/util/xmlstring. HPP> # include <stdlib. h> # include <string> # include <vector> # include <stdex Cept> using namespace STD; using namespace xercesc; Class cxml {public: cxml ();~ Cxml (); xmltransservice: Codes transervicecode; void xmlparser (string &) Throw (STD: runtime_error); Private: xercesc: xercesdomparser * m_domxmlparser; // defines the resolution object }; # endif what does this article absorb? Tid = 151 & goto = lastpost
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.