library(XML)
book<-xmlParse("book.xml")
root <- xmlRoot(book)
(book <- xmlToDataFrame(root))
## author title
## 1 Michael, Lewis Flash Boys: A Wall Street Revolt
## 2 Scott, Patterson The Quants
## 3 Benjamin, Graham ; Jason, Zweig The Intelligent Investor
## link
## 1 http://michaellewiswrites.com/index.html#flash-boys
## 2 https://www.goodreads.com/book/show/7495395-the-quants
## 3 https://www.amazon.com/Best-Sellers-Books-Finance/zgbs/books/2604
## award
## 1 Financial Times and McKinsey Business Book of the Year Nominee for Longlist (2014)
## 2 #71 in Kindle Store
## 3 #1 in Best Sellers in Finance
library(RJSONIO)
if (isValidJSON("book.json"))
book<- fromJSON("book.json", nullValue = NA,
simplify = FALSE )
book.df <- lapply(book, list,stringsAsFactors = FALSE)
author<-c(unlist(book.df[[1]][[1]]$author),unlist(book.df[[2]][[1]]$author),unlist(book.df[[3]][[1]]$author))
title<-c(unlist(book.df[[1]][[1]]$title),unlist(book.df[[2]][[1]]$title),unlist(book.df[[3]][[1]]$title))
award<-c(unlist(book.df[[1]][[1]]$award),unlist(book.df[[2]][[1]]$award),unlist(book.df[[3]][[1]]$award))
link<-c(unlist(book.df[[1]][[1]]$link),unlist(book.df[[2]][[1]]$link),unlist(book.df[[3]][[1]]$link))
author[3]<-paste(author[3],";",author[4])
author<-author[1:3]
data.frame(title,author,award,link)
## title author
## 1 Flash Boys: A Wall Street Revolt Michael, Lewis
## 2 The Quants Scott, Patterson
## 3 The Intelligent Investor Benjamin, Graham ; Jason, Zweig
## award
## 1 Financial Times and McKinsey Business Book of the Year Nominee for Longlist (2014)
## 2 #71 in Kindle Store
## 3 #1 in Best Sellers in Finance
## link
## 1 http://michaellewiswrites.com/index.html#flash-boys
## 2 https://www.goodreads.com/book/show/7495395-the-quants
## 3 https://www.amazon.com/Best-Sellers-Books-Finance/zgbs/books/2604
table <- readHTMLTable("book.html",which = 1)
table
## Title Author
## 1 Flash Boys: A Wall Street Revolt Michael, Lewis
## 2 The Quants Scott, Patterson
## 3 The Intelligent Investor Benjamin, Graham ; Jason, Zweig
## Link
## 1 http://michaellewiswrites.com/index.html#flash-boys
## 2 https://www.goodreads.com/book/show/7495395-the-quants
## 3 https://www.amazon.com/Best-Sellers-Books-Finance/zgbs/books/2604
## Award
## 1 Financial Times and McKinsey Business Book of the Year Nominee for Longlist (2014)
## 2 #71 in Kindle Store
## 3 #1 in Best Sellers in Finance
All three data frames have similar format