From the course: Exploring C Libraries

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Generating XML data

Generating XML data - C Tutorial

From the course: Exploring C Libraries

Start my 1-month free trial

Generating XML data

- The libxml2 library allows you to modify xml data by adding a new element or node. In this code, the sample xml document is updated with a new key and data. After opening and validating the document, a new child node is created for the root node by using the xmlNewTextChild function at line 38. The tag is "spouse" and the content is "Martha". Line 46 saves the updated file, overriding the original. Appropriate messages are output. I've already compiled and linked the program. And the file was updated. Now, let's concatenate it to see what it looks like. And you see the new tag inserted at the last line, it's rather inelegant, but the data is there. To add a new element beyond the top level, the code must search for a specific child tag. Starting at line 37, this code looks for the name element, which is just under the root level in the document. Once found, the xml new text child function at line 44, adds the…

Contents