Editing an XML file in R and saving back to XML

Is there a better way to open an XML file in R, edit (delete a character that occurs that multiple times within the XML file) and then save it back as XML file.

XML reproducible example file copied at the bottom and a snapshot image (below) highlighting where the deletes are needed.

Here is the R code I have so far but don't know how to proceed further.

Blockquote
library(XML);library(xml2);library(methods);library(tidyverse)
#Read one XML file
filepath <- "C:/Users/PeriaPr/Desktop/repex1.xml"
onefile <- xmlTreeParse(gsub("'","",readLines(filepath)),asText = TRUE)
xmlroot <- xmlRoot(onefile)
var <- xmlSApply(xmlroot, function(x) xmlSApply(x, xmlValue))

Here is the XML file

Blockquote

<?xml version = "1.0" encoding = "windows-1252"?>
<action_step step_no="1.3.1.1">
	<step>1</step>
	<title><![CDATA[Part1 - 'Apple']]></title>
	<start><![CDATA[2019/08/09 7:57:17]]></start>
	<duration><![CDATA[0 Hr. 12 Min. 22 Sec.]]></duration>
	<status><![CDATA[Passed]]></status>
</action_step>
<action_step step_no="1.4.1.1">
	<step>2</step>
	<title><![CDATA[Part2 - 'Orange']]></title>
	<start><![CDATA[2019/08/09 8:09:39]]></start>
	<duration><![CDATA[0 Hr. 32 Min. 55 Sec.]]></duration>
	<status><![CDATA[Passed]]></status>
</action_step>	
<action_step step_no="1.5.1.1">
	<step>68</step>
	<title><![CDATA[Part3 - 'Banana']]></title>
	<start><![CDATA[2019/08/09 8:42:35]]></start>
	<duration><![CDATA[0 Hr. 36 Min. 28 Sec.]]></duration>
	<status><![CDATA[Passed]]></status>
</action_step>
<action_step2 secondchild="secondchild">
	<action_step2subchild subchild="subchild">
		<title><![CDATA[Part3 - 'Banana']]></title>
	</action_step2subchild>
</action_step2>	

I can't promise to take a crack at the problem after my recent nasty run-in with XML, but others, following the zen of lazy evaluation might, if you can provide a reproducible example, called a reprex.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.