Http://www.cnblogs.com/flysnail/archive/2012/06/25/2561319.html
----
1. Download and install
Download libxml2, the official website, and download the source code package of the appropriate version.
Http://rpmfind.net/linux/rpm2html/search.php? Query = libxml2-devel
I downloaded the version for libxml2-devel-2.6.32-11.10.i586
Decompress, compile, and run
./Configure-Prefix/usr/local/XML # installation directory
Make
Make install
After the installation is complete, four more folders are generated under/usr/local/XML.
Bin include lib share
Ii. Run demo
Use eclipse to create a C ++ project.
1. Solve the header file path problem.
The libxml header file is automatically added to the default directory. If eclipse is not automatically added, You can manually add it, right-click Properties, and make the following changes.
The header file path after installation is
$/Include/libxml2/libxml/*. h
The default working directory in the source code is <libxml/*. h>.
At this time, the project cannot find these files. What we need to do is to modify the directory.
$/Include/libxml/*. h
Of course, there is also a way to modify the code contained in those header files. For example:
?
#include < libxml/xmlversion.h > |
Change
#include < libxml2/libxml/xmlversion.h >
This method is not so silly to process dozens of headers.
2. Demo SRC
Void writexml (void) {// definition document and node pointer xmldocptr Doc = xmlnewdoc (bad_cast "1.0"); xmlnodeptr root_node = xmlnewnode (null, bad_cast "root "); // set the root node xmldocsetrootelement (Doc, root_node); // directly create the node xmlnewtextchild (root_node, null, bad_cast "newnode1", bad_cast "newnode1 content") in the root node "); xmlnewtextchild (root_node, null, bad_cast "newnode2", bad_cast "newnode2 content"); xmlnewtextchild (root_node, null, bad_cast "Newnode3", bad_cast "newnode3 content"); // create a node, set its content and attributes, and add the root node xmlnodeptr node = xmlnewnode (null, bad_cast "node2 "); xmlnodeptr content = xmlnewtext (bad_cast "node content"); xmladdchild (root_node, node); xmladdchild (node, content); xmlnewprop (node, bad_cast "attribute ", bad_cast "yes"); // create a son and grandson node = xmlnewnode (null, bad_cast "son"); xmladdchild (root_node, node); xmlnodeptr grandson = xmlne Wnode (null, bad_cast "grandson"); xmladdchild (node, grandson); xmladdchild (grandson, xmlnewtext (bad_cast "this is a grandson node ")); // store the XML document int NREL = 0; NREL = xmlsavefile ("createdxml. XML ", DOC); If (NREL! =-1) {cout <"an XML document is created and written to" <NREL <"Byte" <Endl ;} // release the memory xmlfreedoc (DOC) dynamically applied by nodes in the document );}
3. Set lib
Eclipse sets the link path:/usr/local/XML/lib
Set the Connection Library xml2
Add the following parameters during command Compilation:
-L/usr/local/XML/lib/-lxml2
Well, the compilation and execution below will be OK.
Category: Linux develop
Http://www.cnblogs.com/flysnail/archive/2012/06/25/2561319.html
----
1. Download and install
Download libxml2, the official website, and download the source code package of the appropriate version.
Http://rpmfind.net/linux/rpm2html/search.php? Query = libxml2-devel
I downloaded the version for libxml2-devel-2.6.32-11.10.i586
Decompress, compile, and run
./Configure-Prefix/usr/local/XML # installation directory
Make
Make install
After the installation is complete, four more folders are generated under/usr/local/XML.
Bin include lib share
Ii. Run demo
Use eclipse to create a C ++ project.
1. Solve the header file path problem.
The libxml header file is automatically added to the default directory. If eclipse is not automatically added, You can manually add it, right-click Properties, and make the following changes.
The header file path after installation is
$/Include/libxml2/libxml/*. h
The default working directory in the source code is <libxml/*. h>.
At this time, the project cannot find these files. What we need to do is to modify the directory.
$/Include/libxml/*. h
Of course, there is also a way to modify the code contained in those header files. For example:
?
#include < libxml/xmlversion.h > |
Change
#include < libxml2/libxml/xmlversion.h >
This method is not so silly to process dozens of headers.
2. Demo SRC
Void writexml (void) {// definition document and node pointer xmldocptr Doc = xmlnewdoc (bad_cast "1.0"); xmlnodeptr root_node = xmlnewnode (null, bad_cast "root "); // set the root node xmldocsetrootelement (Doc, root_node); // directly create the node xmlnewtextchild (root_node, null, bad_cast "newnode1", bad_cast "newnode1 content") in the root node "); xmlnewtextchild (root_node, null, bad_cast "newnode2", bad_cast "newnode2 content"); xmlnewtextchild (root_node, null, bad_cast "Newnode3", bad_cast "newnode3 content"); // create a node, set its content and attributes, and add the root node xmlnodeptr node = xmlnewnode (null, bad_cast "node2 "); xmlnodeptr content = xmlnewtext (bad_cast "node content"); xmladdchild (root_node, node); xmladdchild (node, content); xmlnewprop (node, bad_cast "attribute ", bad_cast "yes"); // create a son and grandson node = xmlnewnode (null, bad_cast "son"); xmladdchild (root_node, node); xmlnodeptr grandson = xmlne Wnode (null, bad_cast "grandson"); xmladdchild (node, grandson); xmladdchild (grandson, xmlnewtext (bad_cast "this is a grandson node ")); // store the XML document int NREL = 0; NREL = xmlsavefile ("createdxml. XML ", DOC); If (NREL! =-1) {cout <"an XML document is created and written to" <NREL <"Byte" <Endl ;} // release the memory xmlfreedoc (DOC) dynamically applied by nodes in the document );}
3. Set lib
Eclipse sets the link path:/usr/local/XML/lib
Set the Connection Library xml2
Add the following parameters during command Compilation:
-L/usr/local/XML/lib/-lxml2
Well, the compilation and execution below will be OK.