From the course: Exploring C Libraries
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Accessing XML data
- For the color presented in this movie I'll be examining the sample XML file shown here. It contains nested tags, attributes and content. To exam the file in your code use the XML 2 library to parse the XML file. The basic parsing structure is shown here in this source code file. The xmlDocPtr doc variable doc is returned from the xmlParseFile function at line 13. Here I'm only fetching the root element or node shown at line 21. At line 28 the root nodes name is output. I've already compiled and linked the source code so I'm just going to run the program. And you see that the correct root node name person is output In this modification to the code I've added a recursive function dump_elements which is shown at line 45. This function cascades through all the nodes in the XML file displaying each one. The current next variable at line 50 references subsequent nodes similar to the way a linked list works in C. And here…
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.