How to Import different nodes of xml data in R and create data frames

Dear All,

Last week I had started my carrier on R , ANd this is my first post on community.

I had XML file with different nodes such as below.Can any one please help me how can I make data frames with below ifnormaiton

<details>

<employee>
	<id>1212</id>
	<name>asdf</name
</employee>

<contact>
	<telephone>
		<hone>232</home>
		<office>333</office>
	</telephone>
</contact>

<contact>
	<telephone>
		<hone>334</home>
		<office>898</office>
	</telephone>
</contact>

<sal>
	<now>3223</now>
	<past>333</past>
<sal>

<details>

Hi @siddiqali_87,

Welcome. First off, just an FYI, I'm going to move this to General, since it's not about the IDE itself (no big deal, just giving you a heads up)!

As per usual, there's more than one way to approach the problem:

I find the xml2 package to be very helpful (blog post describing it here).

That alone won't get you all the way there, though. My (rare) XML workflow looks something like that described in Jenny's tutorial (below), but depending on how comfortable you are with purrr, it might be overkill for the current problem at hand:

I haven't personally used xmltools, but this tutorial by its author seems to cover it quite nicely, and it seems to have some built in functions that could help you skip some steps: xml_dig_df(), and xml_to_df().

There are a few more examples in its GitHub repo as well:

1 Like