【问题标题】:Reading XML in R [duplicate]在 R 中读取 XML [重复]
【发布时间】:2017-09-25 13:54:48
【问题描述】:

我需要从 R 中的 xml 文档中读取以下值

(http://forecast.weather.gov/MapClick.phplat=29.803&lon=-82.411&FcstType=digitalDWML)

concise-name="tabular-digital" operation-mode="developmental" srsName="WGS 1984"

在所有其他帖子中,他们解释了只读取 xml 对象,对象名称在开头和结尾,数据值在中间。而对于我的问题,我需要读取只有开头且结尾没有 xml 对象的 xml 对象。

让我知道这是否可能。任何帮助或输入表示赞赏。

问候,
莫汉拉杰

【问题讨论】:

  • 完全一样。相同的坐标。
  • @R.Schifini 问题不重复。在已提供的所有链接上,解决方案不是读取列 concise-name、operating-mode 和 srsName 的值。如果你运行代码你就会知道。

标签: r xml


【解决方案1】:

这是我完成这项任务的两个备选方案:

library(XML)
xmlfile <- xmlTreeParse("Your URL to the XML data")
topxml <- xmlRoot(xmlfile) #function to access the top node of yopur file
topxml <- xmlSApply(topxml,function(x) xmlSApply(x, xmlValue)) #To put your data in a data frame
xml_df <- data.frame(t(topxml),row.names=NULL)

您也可以选择不执行所有前面的步骤,这有点复杂,而只执行以下操作:

url <- "Your URL to the XML data"
data_df <- xmlToDataFrame(url)
#or to list
data <- xmlParse("Your URL to the XML data")
xml_data <- xmlToList(data)

DataCamp 对“READ DATA IN R”的贡献

【讨论】:

  • 感谢您的信息。但是,它并没有给我我期望的解决方案。无论如何谢谢。
猜你喜欢
  • 1970-01-01
  • 2012-01-21
  • 1970-01-01
  • 2015-06-08
  • 2021-02-27
  • 2015-07-01
  • 2011-10-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多