I have an XML database, that have structure like this:
<Record>
<Id>
{text}
<AdresDoDoreczen>
<Miejscowosc>
{text}
<Budynek>
{text}
<KodPocztowy>
{text}
<Poczta>
{text}
<Gmina>
{text}
<Powiat>
{text}
<Wojewodztwo>
{text}
I use following code:
require(xml2)
file <- "file.xml"
doc <- read_xml(file, useInternalNodes = TRUE)
column1 = xml_text(xml_find_all(doc, '//AdresDoDoreczen/Miejscowosc'))
Applying this code to other nodes (Budynek, Powiat, Gmina) gives me a number of vectors/columns, that I can merge with matrix()
and save it as .csv.
Unfortunately, few of those records are missing some nodes, so xml_find_all(doc, '//AdresDoDoreczen/Gmina')
gives me not 100 records, but 95. It works fine when "Gmina" node is empty, but when it doesnt exist at all - I have a problem, because then whole Vector matrix is missaligned.
Any idea how to deal with those?