How to read and Convert XML data into R?


#1

Hello All,

Good evening,

My offered data comes with one column the below shown format .I have to extract the (d13,d14…etc )information from each observation as shown in below

this is my head data

class(FData$DetailData)—Showing as Factor

head(FData$DetailData)
[1] ?<dcs><d13>true</d13><d14>1995</d14><d20>1490</d20><d34>2</d34><d36>true</d36><d47>true</d47><d52>true</d52><d55>350</d55><d56>1140</d56><d60>2.50</d60><d62>true</d62><d80>75</d80><d89>66</d89><d90>71</d90><d91>75</d91><d92>80</d92><d94>92</d94><d104>8.0</d104></dcs>
[2] ?<dcs><d14>1928</d14><d20>3345</d20><d34>2</d34><d55>240</d55><d56>3105</d56><d80>97</d80><d89>65</d89><d90>71</d90><d91>75</d91><d92>80</d92><d94>92</d94></dcs>                                                                                                          
[3] ?<dcs/>                                                                                                                                                                                                                                                                    
[4] ?<dcs><d13>true</d13><d20>1340</d20><d34>3</d34><d36>true</d36><d37>true</d37><d47>true</d47><d55>220</d55><d56>1120</d56><d68>true</d68><d80>84</d80><d86>49</d86><d89>65</d89><d91>75</d91><d94>93</d94><d97>1</d97></dcs>                                               
[5] ?<dcs><d20>990</d20><d34>2</d34><d37>true</d37><d47>true</d47><d55>200</d55><d56>790</d56><d86>49</d86><d91>75</d91><d94>92</d94><d97>1</d97></dcs>                                                                                                                        
[6] ?<dcs><d13>true</d13><d20>1410</d20><d34>1</d34><d36>true</d36><d37>true</d37><d55>190</d55><d56>1220</d56><d86>50</d86><d89>66</d89><d91>76</d91><d92>79</d92><d94>91</d94><d97>1</d97></dcs>                                                                             
44207 Levels: ?<dcs/> ...

How i have to read the above variable as Xml in R to Extract Data.

I tried with some outside XML data extraction uinsg R it is working nicely But

How to read and work on this kind of input i am not getting

I need the output

d13 d14 … etc

true 1995 …
null 1928
null NULL
true NUll

can any one plese help on this

Regards,
Raghavendra


#2

You can use the xmlSApply function in the ‘xml’ package in R.

For a deeper understanding and multiple examples explaining the approach click here.