Reading XML files in R: UTF-8 and Umlaut



I want to import some xml file with some german text including umlauts (like ä, ö, ü, &, "). But somehow i cant get a proper import. Im using RStudio and the XML Package, here is what i do: Example XML-File (edited example from wikipedia):



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<verzeichnis>
<titel>Wikipedia Städteverzeichnis</titel>
<eintrag>
<stichwort>Genf</stichwort>
<eintragstext>Genf ist der Sitz von ä ü ö &amp; ...</eintragstext>
</eintrag>
</verzeichnis>


Import of XML File



doc <- xmlParse('data/example.xml', useInternalNodes=TRUE)


Result



> doc
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<verzeichnis>
<titel>Wikipedia Städteverzeichnis</titel>
<eintrag>
<stichwort>Genf</stichwort>
<eintragstext>Genf ist der Sitz von ä ü ö &amp;...</eintragstext>
</eintrag>
</verzeichnis>


So obviously the umlauts are not imported correctly, how do i fix it?


No comments:

Post a Comment