You can convert back to UTF-8:

value <- unlist(xpathApply(doc,"//MESSUNG/BEZEICHNUNG", xmlValue))
Encoding(value) <- "UTF-8"

On Thu, Sep 3, 2009 at 7:56 AM, Dominik Bänninger <baenni@kiecks.de> wrote:

> Dear list
> I tried to read an xml file using the xml package. Unfortunately, some
> encoding problems occure. E.g. german Umlaut will be red correctly. I assume
> that the occurs due to (internal?) conversion to utf-8. To illustrate the
> problem, I have wrote to xml files.
> File Test 1
> -----------
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <Daten>
>  <ITEM>
>  <Messdaten>
>    <MESSUNG>
>    <BEZEICHNUNG>Länge</BEZEICHNUNG>
>   </MESSUNG>
>  </Messdaten>
>  </ITEM>
> </Daten>
>
> File Test 2
> -----------
> <?xml version="1.0" encoding="utf-8"?>
> <Daten>
>  <ITEM>
>  <Messdaten>
>    <MESSUNG>
>    <BEZEICHNUNG>Länge</BEZEICHNUNG>
>   </MESSUNG>
>  </Messdaten>
>  </ITEM>
> </Daten>
> The following code shows that i cannot extract the Value of  "Länge"
> correctly. Any help is very welcom.
> ----------------------------------------  Code Start ------------
> > fname1 <- "test1.xml"
> > fname2 <- "test2.xml"
> > doc <- xmlTreeParse(fname1,useInternalNodes=T)
> > show(doc)
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <Daten>
>  <ITEM>
>    <Messdaten>
>      <MESSUNG>
>        <BEZEICHNUNG>Länge</BEZEICHNUNG>
>      </MESSUNG>
>    </Messdaten>
>  </ITEM>
> </Daten>
> > xpathApply(doc,"//MESSUNG/BEZEICHNUNG", xmlValue)
> [[1]]
> [1] "LÃ¤nge"
> > doc <- xmlTreeParse(fname2,useInternalNodes=T)
> > show(doc)
> <?xml version="1.0" encoding="utf-8"?>
> <Daten>
>  <ITEM>
>    <Messdaten>
>      <MESSUNG>
>        <BEZEICHNUNG>LÃ¤nge</BEZEICHNUNG>
>      </MESSUNG>
>    </Messdaten>
>  </ITEM>
> </Daten>
> > xpathApply(doc,"//MESSUNG/BEZEICHNUNG", xmlValue)
> [[1]]
> [1] "LÃ¤nge"
> ----------------------------------------  Code Stop ------------
> I am using the following system.
> R version 2.9.1 (2008-06-26)
> Copyright (C) 2008 The R Foundation for Statistical Computing
> ISBN 3-900051-07-0
>
> Microsoft Windows XP
> XML_2.6-0.zip downloaded from
> http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.9/
>
>        [[alternative(swapped) HTML version deleted]]
>
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>


-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]


