[R] Extracting XML value

Glenn Schultz glennmschultz at me.com
Thu Sep 3 17:23:16 CEST 2015


I have made it as far as generating an api call which returns the following xml
[1] "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<observations realtime_start=\"2015-09-03\" realtime_end=\"2015-09-03\" observation_start=\"2015-09-01\" observation_end=\"2015-09-01\" units=\"lin\" output_type=\"1\" file_type=\"xml\" order_by=\"observation_date\" sort_order=\"asc\" count=\"1\" offset=\"0\" limit=\"100000\">\n  <observation realtime_start=\"2015-09-03\" realtime_end=\"2015-09-03\" date=\"2015-09-01\" value=\"0.46\"/>\n</observations>\n\n\n\n"
"text/xml"    "UTF-8" 

following DTL's presentation on the Berkley site and the package help I parsed the xml

doc = xmlTreeParse(USSW10, asText = TRUE, useInternal = TRUE)

which gives
<?xml version="1.0" encoding="utf-8"?>
<observations realtime_start="2015-09-03" realtime_end="2015-09-03" observation_start="2015-09-01" observation_end="2015-09-01" units="lin" output_type="1" file_type="xml" order_by="observation_date" sort_order="asc" count="1" offset="0" limit="100000">
  <observation realtime_start="2015-09-03" realtime_end="2015-09-03" date="2015-09-01" value="0.46"/>

finally I try to extract the value 0.46 using the xmlValue function.  I have lost something in translation and I am unable to extract the value.  my understanding is I have one node with no children, correct?


More information about the R-help mailing list