R解析xml文件
library(XML)
# 解析XML文件
doc <- xmlParse('/home/xuefliang/Dropbox/xin.xml')
url <- unlist(getNodeSet(doc,"//enclosure/@url"),use.names = T)
title <- unlist(getNodeSet(doc,"//title/text()"),use.names = FALSE)
df <- data.frame(url)
write.csv(df,'/home/xuefliang/xin.csv')
library(xml2)
doc <- read_xml('/home/xuefliang/Downloads/xin.xml')
#xml_name(doc)
#xml_text(doc)
xml_find_all(doc, ".//enclosure/@url")[]
# 解析XML文件
doc <- xmlParse('/home/xuefliang/Dropbox/xin.xml')
url <- unlist(getNodeSet(doc,"//enclosure/@url"),use.names = T)
title <- unlist(getNodeSet(doc,"//title/text()"),use.names = FALSE)
df <- data.frame(url)
write.csv(df,'/home/xuefliang/xin.csv')
library(xml2)
doc <- read_xml('/home/xuefliang/Downloads/xin.xml')
#xml_name(doc)
#xml_text(doc)
xml_find_all(doc, ".//enclosure/@url")[]
评论
发表评论