Use of libxml2 in Fedora

Source: Internet
Author: User
1. Download and install libxml2. Download the source code package of your own version from the official website. Http://rpmfind.net/linux/rpm2html/search.php? Query = libxml2-devel I download the version for the libxml2-devel-2.6.32-11.10.i586 decompress, compile and run./configure & ndash; prefix/usr/local/xml # Install

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 working directory in the source code is

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" <
 
  

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.

Upgrade Linux built-in libxml2 library install php-5.2.5 http://www.linuxidc.com/Linux/2008-05/12749.htm on RedHat Linux

Ubuntu libxml2 http://www.linuxidc.com/Linux/2007-10/8075.htm

Libxml2 use http://www.linuxidc.com/Linux/2014-01/95402.htm in Linux

Use arm-none-linux-gnueabi to cross-compile libxml2 http://www.linuxidc.com/Linux/2014-05/101902.htm in Ubuntu

For more information about Fedora, see Fedora topics page http://www.linuxidc.com/topicnews.aspx? Tid = 5

This article permanently updates the link address: Http://www.linuxidc.com/Linux/2014-05/101903.htm

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.