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
- 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Understanding XML2m 23s
-
(Locked)
Testing the libxml2 installation3m 10s
-
(Locked)
Accessing XML data3m 26s
-
(Locked)
Generating XML data3m 57s
-
(Locked)
Working with JSON2m 39s
-
(Locked)
Testing the json-c installation3m 17s
-
(Locked)
Accessing JSON data3m 10s
-
(Locked)
Reading JSON data3m 46s
-
(Locked)
Creating JSON output3m 35s
-
-
-
-
-