From the course: Exploring C Libraries

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Solution: Converting data formats

Solution: Converting data formats - C Tutorial

From the course: Exploring C Libraries

Solution: Converting data formats

(bright music) - [Instructor] Here's my solution for this chapter's challenge, which is to extract XML data and generate a JSON-formatted version. The code uses two functions, add_json_string, which is borrowed from one of the videos in this chapter, and fetchParentChild, which is built upon a function presented in this chapter but customized to find child values for a specific parent. Here in the main function, I declare a slew of constants. All these are in one location, which makes it easier for me to update the code in the future. Here is the source file name, and then I have xml_parent tag and the two child tags as constants, and the fields that are required for the JSON format. They're all in one place, which keeps them handy. The step one portion of the code extracts the name/first and name/last items from the XML data. These first two blocks of code follow the general pattern of reading an XML file as presented in this course. So open and parse the file, fetch the root…

Contents