Skip to content
Prev 172185 / 398506 Next

Need help extracting info from XML file using XML package

Don MacQueen wrote:
try

    lapply(
       xpathSApply(doc, '//Polygon',
          xpathSApply, '//coordinates', function(node)
              strsplit(xmlValue(node), split=',|\\s+')),
       as.numeric)

which should find all polygon nodes, extract the coordinates node for
each polygon separately, split the coordinates string by comma and
convert to a numeric vector, and then report a list of such vectors, one
vector per polygon.

i've tried it on some dummy data made up from your example below.  the
xpath patterns may need to be adjusted, depending on the actual
structure of your xml file, as may the strsplit pattern.

vQ