Apologies for a question which may have a simple solution, I am not very experienced at using R and this is the first time I have dealt with XML data imports.
I have been searching for a solution to the problem but had no luck – I am looking to convert an XML to a dataframe. A lot of the solutions I have come across give examples of the XML element tags which are in the same format as VAR2 below.
The code I have at the moment is below which uses the XML package and xmlToDataFrame function. This returns a value for VAR2 but empty column for VAR3. How can I import an XML as a dataframe which uses a format similar to VAR3?
Any help would be greatly appreciated. Whilst I am using the XML package at the moment I am open to other packages to get to a solution.
Thanks,
doc <- “
<DATA>
<GROUP>
<VAR1 Val="ID0001"/>
<SUBGROUP>
<VAR2>ABCDEF</VAR2>
<VAR3 Val="500"/>
</SUBGROUP>
</GROUP>
</DATA>
doc_parse <- xmlParse(doc)
doc_frame <- xmlToDataFrame(doc_parse, nodes = getNodeSet(doc_parse, "//SUBGROUP"))