Wednesday, 15 April 2015

How to get data I need from CDATA part using R -



How to get data I need from CDATA part using R -

now have info need xml file. info in cdata part painful get. info in format followings:

<?xml version="1.0"?> -<calc> <marketdata> <![cdata[interestrate.chf,type=,floor=<undefined>,currency=chf, curve=[(1,0.1),(2,0.1)...(15,0.1)] interestrate.eur,type=,floor=<undefined>, currency=eur,curve=[...] interestratevol.chf,type=,longrunmean=0.01,..]]> </marketdata> <calendars>..... </calendars> </calc>

like want curve info of interestrate.eur. how should in r? need have locate "interestrate.eur" first, grab info after first "curve". suggestion deal cdata? or other language can work out problem.

xdata <- '<?xml version="1.0"?> <calc> <marketdata> <![cdata[interestrate.chf,type=,floor=<undefined>,currency=chf, curve=[(1,0.1),(2,0.1)...(15,0.1)] interestrate.eur,type=,floor=<undefined>, currency=eur,curve=[...] interestratevol.chf,type=,longrunmean=0.01,..]]> </marketdata> <calendars>..... </calendars> </calc>' library(xml) xdata <- xmlparse(xdata) cdata <- xpathsapply(xdata, "//text()", xmlvalue) > cdata[1] [1] "interestrate.chf,type=,floor=<undefined>,currency=chf,\n curve=[(1,0.1),(2,0.1)...(15,0.1)] interestrate.eur,type=,floor=<undefined>,\n currency=eur,curve=[...] interestratevol.chf,type=,longrunmean=0.01,.." out <- strsplit(cdata[1], ' ')[[1]] > out[out != ""] [1] "interestrate.chf,type=,floor=<undefined>,currency=chf,\n" [2] "curve=[(1,0.1),(2,0.1)...(15,0.1)]" [3] "interestrate.eur,type=,floor=<undefined>,\n" [4] "currency=eur,curve=[...]" [5] "interestratevol.chf,type=,longrunmean=0.01,.."

r cdata

No comments:

Post a Comment