For details about libxml2 library viewing method please refer to: blog. csdn. netwangkai_123456articledetails25710971libxml2 library Installation Method: sudoapt-getinstalllibxml2sudoapt-getinstalllibxml2-dev using the above command after installing the software package can use the following command to view the software
For details about how to view libxml2 library, please refer to: http://blog.csdn.net/wangkai_123456/article/details/25710971 libxml2 library installation method: sudo apt-get install libxml2 sudo apt-get install libxml2-dev the following command can be used to view the software after installing the software package with the above command
For more information about the libxml2 library, see: http://blog.csdn.net/wangkai_123456/article/details/25710971
How to install the libxml2 library:
Sudo apt-get install libxml2
Sudo apt-get install libxml2-dev
After installing the software package using the preceding command, you can use the following command to check the status of the software package (determine whether the installation is successful)
Libxml2-dev dpkg-s
You can also run the following command (the result is the same ):
Dpkg-query-s libxml2-dev
After the software is installed, the header files of libxml2 are stored in the/usr/include/libxml2/libxml directory by default, this information can be viewed using the following two commands (any command can view the relevant information)
Dpkg-L libxml2-dev
Xml2-config -- cflags
Libxml2 library files are placed in the/usr/lib/i386-linux-gnu Directory, which can be viewed using the following two commands (any command can view the relevant information)
Dpkg-L libxml2-dev
Xml2-config -- libs
The corresponding libxml2 has a tool named xml2-config, the directory where the xml2-config is located is/usr/bin, in fact this is a shell script, detailed information about the xml2-config can be viewed through the following command
Man xml2-config
After the libxml2 library is installed, you can start development based on the libxml2 library. Currently, the following program is named CreateXmlFile. c, which is developed based on the libxml2 library. The Code is as follows:
/********************************* Created: filename: createXmlFile. cauther: wang kaidepend: libxml2.libpurpose: create an xml file **********************************/# include
# Include
# Include
Int main (int argc, char ** argv) {// Define document pointerxmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0"); // Define node pointerxmlNodePtr root_node = xmlNewNode (NULL, BAD_CAST "root"); // Set the root element of the documentxmlDocSetRootElement (doc, root_node); // Create child nodes directly in the root nodexmlNewTextChild (root_node, NULL, BAD_CAST "newnode1", BAD_CAST "newnode1 content"); xmlNewTextChild (root_node, NU LL, BAD_CAST "newnode2", BAD_CAST "newnode2 content"); // Create a new nodexmlNodePtr node = xmlNewNode (NULL, BAD_CAST "node2 "); // Create a new text nodexmlNodePtr content = xmlNewText (BAD_CAST "node content"); // Add a new node to parentxmlAddChild (root_node, node); xmlAddChild (node, content ); // Create a new property carried by a nodexmlNewProp (node, BAD_CAST "attribute", BAD_CAST "yes"); // Create a son and grandson Node elementnode = xmlNewNode (NULL, BAD_CAST "son"); xmlAddChild (root_node, node); xmlNodePtr grandson = xmlNewNode (NULL, BAD_CAST "grandson"); xmlAddChild (node, grandson ); xmlAddChild (grandson, xmlNewText (BAD_CAST "THis is a grandson node"); // Dump an XML document to a fileint nRel = xmlSaveFile ("CreatedXml. xml ", doc); if (nRel! =-1) printf ("an xml document was created and written to % d bytes \ n", nRel); // Free up all the structures used by a document, tree includedxmlFreeDoc (doc); // printf ("Hello World! \ N "); return 0 ;}
The following command can be used to compile this program:
Gcc-I/usr/include/libxml2 CreateXmlFile. c-o CreateXmlFile-L/usr/lib/i386-linux-gnu-lxml2
Here, the-I parameter is used to specify the path of the gcc compiler to find the header file, the-L parameter is used to specify the path of the libxml2 library file, and the final
-Lxml2 specifies the specific library file. (-Lxml2 must be placed at the end of the command, otherwise the error of finding the Link Library will occur, as shown in)
I have not figured out the specific reason why I must put-lxml2 at the end. Further research is required.
The compilation command can also be written as follows:
Gcc 'xml2-config -- cflags '-L/usr/lib/i386-linux-gnu CreateXmlFile. c-o CreateXmlFile-lxml2
Or
Gcc 'xml2-config -- cflags 'CreateXmlFile. c-o CreateXmlFile-L/usr/lib/i386-linux-gnu-lxml2
Or
Gcc CreateXmlFile. c-o CreateXmlFile 'xml2-config -- cflags -- libs'
Although the form is different, the actual content of the command is the same. Because the command xml2-config -- the execution result of cflags is
-I/usr/include/libxml2 (specify the directory of the include header file)
Command xml2-config -- libs execution result is
-L/usr/lib/i386-linux-gnu-lxml2 (specifies the directory where libxml2 library files are located and the specific library files)
(Whatever the form, you only need to ensure that-lxml2 is at the end of the compiled command)