0

I need to read the below values from the xml document in R

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

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

In all the other posts they have explained only reading the xml objects with object names at both beginning and at the end with data value in the middle. whereas here for my problem i need to read xml objects which has only the beginning and has no xml object at the end.

Let me know is this possible. Any help or input is appreciated.

Regards,
Mohanraj

Mohan Raj
  • 77
  • 1
  • 2
  • 9
  • It's an exact duplicate. Same coordinates. – R. Schifini Sep 25 '17 at 14:01
  • @R.Schifini The question is not duplicate. On all the links which has been provided the solution is not give to read the values of columns concise-name, operational-mode and srsName. If you run the code you will come to know. – Mohan Raj Sep 25 '17 at 14:18

1 Answers1

0

These are my two alternatives for this task:

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)

You can also choose not to do all the previous steps, which are a bit more complicated, and to just do the following:

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)

Credits to "READ DATA IN R" by DataCamp

Fábio
  • 771
  • 2
  • 14
  • 25