replace numbers inside an XML element using xmlValue



I have bunch of numbers



preKId_2015 = c(242938L, 339402L, 361888L, 428033L, 442546L, 309790L, 355662L,
458179L, 465105L, 490383L, 524644L, 526614L, 539453L, 555516L,
569709L)


I have an xml file with some other id values already between the elements



<input-id>
"PreKId"
12344
33433
23343
93893
23333
</input-id>


I am trying to replace these pre-existing values with the values form preKId_2015. I tried



doc <- xmlParseDoc("C:/... ProjectKids/test12.xml")
nodes <- getNodeSet(doc, "//input-id")[[1]]
xmlValue(nodes) = replace(xmlValue(nodes),xmlValue(nodes),preKId_2015)


I get a warning and nothing happens



Warning message:
In replace(xmlValue(nodes), xmlValue(nodes),preKId_2015) :
number of items to replace is not a multiple of replacement length


Need help


No comments:

Post a Comment