r - Accessing children elements of XML -
i have xml document
require(xml) url <- "http://stats.oecd.org/restsdmx/sdmx.ashx/getdata/sna_table1/nor+can+fra+deu+gbr+usa+ita+jap.b1_ga+b1g_p119+b1g+b1gva+b1gvb_e+b1gvc+b1gvf+b1gvg_i+b1gvj+b1gvk+b1gvl+b1gvm_n+b1gvo_q+b1gvr_u+d21_d31+d21s1+d31s1+db1_ga.cxc/all?starttime=1950&endtime=2013" xml <- xmlparse(url)
which trying access.
i can access root element
getnodeset(xml, "//message:messagegroup")
but can't descend 3 parse elements dataset/series
.
getnodeset(xml, "//message:messagegroup/dataset/series")
returns empty list. problem namespace of document?
yes. problem default namespace. need give name in order able select nodes it. can this
xml <- xmlparse(url) ns<-xmlnamespacedefinitions(xml, simplify=t) names(ns)[1] <- "def" #assign name "def"
then can do
getnodeset(xml, "//message:messagegroup/def:dataset/def:series", namespaces=ns)
Comments
Post a Comment