如何使用R替换XML节点

如何使用R替换XML节点,r,xml,R,Xml,我正在使用包“XML”在R中创建一个XML文件 这是我的R代码 library(XML) xmlWARN <- xmlParse(strWarningXMLFileName) xmlWARN <- xmlRoot(xmlWARN) newXMLNode("StartDateTime", format(min(MyData$timestamp),"%m/%d/%Y %H:%M"), parent = xmlWARN) newXMLNode("EndDateTime", f

我正在使用包“XML”在R中创建一个XML文件

这是我的R代码

library(XML)
xmlWARN <- xmlParse(strWarningXMLFileName)
xmlWARN <- xmlRoot(xmlWARN)
newXMLNode("StartDateTime", format(min(MyData$timestamp),"%m/%d/%Y %H:%M"), parent = xmlWARN)       
newXMLNode("EndDateTime", format(max(MyData$timestamp),"%m/%d/%Y %H:%M"), parent = xmlWARN)
newXMLNode("Granularity", strGranularity, parent = xmlWARN)
newXMLNode("TimeGapInData",blnTimeSlotGaps , parent = xmlWARN)
newXMLNode("TimeGapInDataIntervals",intNumberOfMissingTimeslots , parent = xmlWARN)
newXMLNode("IncompleteTimespan",blnIncompleteTimeSpan , parent = xmlWARN)
saveXML(xmlWARN, strWarningXMLFileName)
库(XML)
xmlWARN希望这有帮助

library(XML)
#test.xml is the xml file where you want to make changes
xml_doc = xmlParseDoc("test.xml")
#replace the value of 'ServerName' node
invisible(replaceNodes(xml_doc[["//Server-Block//ServerName/text()"]], newXMLTextNode("YourServer")))
xml_doc


别忘了告诉我们它是否解决了您的问题:)

@user7945126如果它解决了您的问题,那么您应该将其标记为正确答案。它肯定会帮助其他人,以防他们将来面临类似的问题。谢谢我试图改变内容,但没有成功。你能帮忙吗?mysharepointserver.com/sites/mysite/myfile.txt automatic update 0@RanonKahn请创建一个新帖子,以便其他人也能提供帮助。顺便说一句,您可能对这个XPath定义感兴趣-
'/*[name()=“soap:Envelope”]
实际上我昨天在这里创建了一篇文章@RanonKahn让我们试试这个-
库(XML);xml_doc=xmlParseDoc(“test.xml”);不可见(replaceNodes)(getNodeSet(xml_doc,“//ns:checkinfle//ns:pageUrl/text()”,c(ns=)http://schemas.microsoft.com/sharepoint/soap/)[[1]],newXMLTextNode(“YournewPageUrl”);xml\u doc
。希望有帮助!
<ServerName>MyServer</ServerName>
<ServerName>YourServer</ServerName>
library(XML)
#test.xml is the xml file where you want to make changes
xml_doc = xmlParseDoc("test.xml")
#replace the value of 'ServerName' node
invisible(replaceNodes(xml_doc[["//Server-Block//ServerName/text()"]], newXMLTextNode("YourServer")))
xml_doc