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 - 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…
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
-
(Locked)
Challenge: Converting data formats1m 45s
-
(Locked)
Solution: Converting data formats3m 45s
-
-
-
-
-