Hi, I have an existing XML document on disk, which I'd like to use as a template, and exchange a subnode with my own newly created subtree:
<?xml version="1.0"?> <Duncan> <name a="1" b="xyz"> <first>Duncan</first> <last>Temple Lang</last> </name> </Duncan> created by e.g. library(XML) tr <- xmlTree("Duncan") tr$addTag("name", attrs=c(a=1,b="xyz"), close=F) tr$addTag("first", "Duncan") tr$addTag("last", "Temple Lang") tr$closeTag() cat(saveXML(tr)) And now imagine I want to change <first>Duncan</first> into e.g. <initials>D.</initials>. How to do that ? I am able to add my node: library(XML) x <- xmlTreeParse("duncan.xml", useInternalNodes = TRUE) # find parent, add as last child: name <- getNodeSet(x, "//name")[[1]] newXMLNode("initials", "D.", parent=name) first <- getNodeSet(x, "//first")[[1]] # wanted: # deleteXMLNode(name) # or # replaceXMLNode("initials", "D.", replace=first) cat(saveXML(x)) free(x) As seen above: how do I get rid of (no offense meant ;-) <first>Duncan</first> ? Alternatively, how do I overwrite <first>...</first> with my own stuff ? I checked the provided examples, and grep'ed the manpages, to no avail. Thanks in advance, yours, Steffen
signature.asc
Description: This is a digitally signed message part
______________________________________________ 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.