[R] XML package: modify info of internal node
Moreno Coco
mcoco at staffmail.ed.ac.uk
Wed Feb 15 12:44:06 CET 2012
Dear All,
I have a very simple question to which I did not find any
answer online (apologize if it exists).
I have an XML file (attached) on which I just want
to modify the info of a node.
So, I load my xml file:
current = xmlTreeParse(file, useInternalNodes=T)
and I want to change the information of:
<filename>1.jpg</filename>
to be, for example: 1-1.jpg (newname)
I do:
xmlValue( xpathApply( current, "/annotation/filename")[[1]] ) = newname
now, the crazy thing is that it does the change to the xml
but it also through the following error:
Error in xmlValue(xpathApply(current, "/annotation/filename")[[1]]) =
newname : could not find function "xpathApply<-"
it seems that it works, but for a mysterious reason, it also
seems that it does not work.
Since I have to apply this change many times, and write
the resulting modified .xmls, the loop would stop as a
result of the error...
what am i missing here? is there any simpler way to do it?
thanks a lot for your kind help,
Moreno
P.S. I also try:
xmlSApply(xpathApply( current, "/annotation/filename")[[1]], xmlValue)
= newname
obtaining the same result.
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
More information about the R-help
mailing list