Retrieve CPI from data.gov

March 13, 2016

189 views
59 downloads


Report Abuse
This experiment dynamically retrieves XML data from data.gov for CPI and converts XML to data.frame
This experiment uses XML library to retrieve CPI data in XML format using data.gov APIs as described [https://catalog.data.gov/dataset/consumer-price-index/resource/841f4bfc-6cb9-404f-8932-8b3cb07fd852][1]. This experiment then finds the number of records in the XML using XMLSize command. Once it knows the total records, it parses each record and converts each record to individual row of Year, Month and CPI values. It uses XMLParse to parse the HTML content. It uses XMLRoot to find the root of XML and then it traverses each node to retrieve specific elements such as Year, Month and CPI. It uses XMLToList to convert the final XML leaf node to list which is then converted to the numeric value. [1]: https://catalog.data.gov/dataset/consumer-price-index/resource/841f4bfc-6cb9-404f-8932-8b3cb07fd852