library(XML)
doc <- xmlParse('/media/Data/skola/dipl/mendeley.xml')
records <- getNodeSet(doc, '//record')
records[1]
fix(doc)
records[2]
records[11]
getNodeSet(records[[1]], '//title')
str(recores)
str(records)
str(records[[1]])
head(getNodeSet(records, '//title'))
head(getNodeSet(records[[1]], '//title'))
head(getNodeSet(records[[2]], '//title'))
class(records)
str(records)
records[[1]]
str(records[[1]])
length(records)
?getNodeSet
?xmlElementsByTagName
?XML
??XML
records <- getNodeSet(doc, '//records')
fix(records)
xmlApply(records, function(x) getNodeSet(x, 'title'))
records <- getNodeSet(doc, '//record')
records[[1]]
class(records[[1]])
xmlElementsByTagName(records[[1]], 'title', T)
sapply(records, xmlElementsByTagName, 'title', T)
x <-sapply(records, xmlElementsByTagName, 'title', T)
length(x)
str(x)
?xmlValue
x <-sapply(records, function(x) xmlValue(xmlElementsByTagName(x, 'title', T)))
x <-sapply(records, function(x) xmlValue(unlist(xmlElementsByTagName(x, 'title', T))))
x <-sapply(records, function(x) xmlElementsByTagName(x, 'title', F))
x
x <-sapply(records, function(x) xmlElementsByTagName(x, 'titles/title', F))
x
records[[1]]
x <-sapply(records, function(x) xmlElementsByTagName(x, 'title', T))
x[[1]]
str(x[[1]])
x[[1]]
xmlValue(x[[1]])
?xmlApply
x <- xmlApply(records, function(x) xmlElementsByTagName(x, 'title', T))
records <- getNodeSet(doc, '//records')
x <- xmlApply(records[[1]], function(x) xmlElementsByTagName(x, 'title', T))
str(x)
x <-sapply(records, function(x) xmlElementsByTagName(x, 'title', T))
x
records <- getNodeSet(doc, '//record')
x <- sapply(records, function(x) xmlElementsByTagName(x, 'title', T))
x
records <- getNodeSet(doc, '//records')
x <- xmlApply(records[[1]], function(x) xmlElementsByTagName(x, 'title', T))
str(x)
x <- xmlApply(records[[1]], function(x) xmlValue(xmlElementsByTagName(x, 'title', T)))
x <- xmlApply(records[[1]], function(x) xmlValue(xmlElementsByTagName(x, 'title', T)[[1]]))
x
x <- xmlSApply(records[[1]], function(x) xmlValue(xmlElementsByTagName(x, 'title', T)[[1]]))
x
str(x)
namex(x) <- NULL
names(x) <- NULL
x
records[[1]]
x <- xmlSApply(records[[1]], function(x) xmlValue(xmlElementsByTagName(x, 'year', T)[[1]]))
x <- xmlSApply(records[[1]], function(x) xmlElementsByTagName(x, 'year', T))
length(x)
x
apply(x, length)
sapply(x, length)
getFirstElementValue <- function(node, name) {
elem <- xmlElementsByTagName(node, name, T)
if (length(elem) == 0) return("")
xmlValue(elem[[1]])
}
getFirstElementValue(records, 'title')
getFirstElementValue(records[[1]], 'title')
x <- xmlSApply(records[[1]], function(x) getFirstElementValue(node, 'title'))
x <- xmlSApply(records[[1]], function(x) getFirstElementValue(x, 'title'))
x
length(x)
x <- xmlSApply(records[[1]], function(x) getFirstElementValue(x, 'year'))
length(x)
x
records
x <- xmlSApply(records[[1]], function(x) getFirstElementValue(x, 'author'))
x
length(x)
authors <- xmlSApply(records[[1]], function(x) getFirstElementValue(x, 'author'))
years <- xmlSApply(records[[1]], function(x) getFirstElementValue(x, 'year'))
titles <- xmlSApply(records[[1]], function(x) getFirstElementValue(x, 'title'))
pages <- xmlSApply(records[[1]], function(x) getFirstElementValue(x, 'pages'))
volumes <- xmlSApply(records[[1]], function(x) getFirstElementValue(x, 'volume'))
journals <- xmlSApply(records[[1]], function(x) getFirstElementValue(x, 'full-title'))
paste(1:5, '.', 5:9)
articles <- data.frame(author=authors, year=years, comment=rep('OK', length(authors)),
full=paste0(titles, ', ', journals, ' ', volumes, ' / ', pages))
rstudio::viewData(articles)
write.table(articles, '/media/Data/skola/dipl/litU/mendeley.txt')
write.table(articles, '/media/Data/skola/dipl/litU/mendeley.txt', row.names=F)
