I'm trying to get the description from that XML using R but I'm having a hard time doing that.
As not all XML have all their parameters, I can not "wire" the position of the description, no just because there could be no description, but also because tha lack of another parameter may change the index of the description .
I need a way to "search" for that xml that have the word description on its attributes.
require(stringr)
library("rjson")
require(XML)
cat("\014")
gc()
isbn <- 9788426379696
key <- 'd231aa37c9b4f5d304a60a3d0ad1dad4'
descripcion_librarything <- function( isbn_num ,APIKey ){
url <- "http://www.librarything.com/services/rest/1.1/?method=librarything.ck.getwork&isbn="
url<- paste(url,isbn_num, "&apikey=", APIKey, sep = "")
data <- xmlParse(url)
xml_data <- xmlToList(data)
class(xml_data)
#<field type="14" name="description" displayName="Description">
xml_data$ltml$item$author$text
xml_data$ltml$item$commonknowledge$fieldList[17]$field$versionList$version$factList$fact
doc = xmlInternalTreeParse(url)
hasSentence = xpathApply(doc, "description")
xpathApply(doc, "description")
doc = xmlTreeParse(url)
xmlAttrs(xmlRoot(doc)[[1]][[1]][[5]][[1]][[17]])
str <- null
return(str)
}
descripcion_librarything (isbn, key)
thanks in advance !
Loop through the xml data<- xmlToList(data), like this: