Update (Remove Nodes/Update Value) in XML Document

studio
help
xml

#1

Hi Everyone…

I’m working with XML and have the following questions. Finding challenging in traversing the xml document… The requirement I have is that I need to

  • Update Value for every “First Child Under Task”
  • Delete 2nd and 3rd… nnnn Text Element from Task

I have de-serialized my xml and I have an XMLDocument with type XDocument already…

My XML

<Document>
	<Task>
		<Text>This is an Example </Text>  <!-- value of this needs to be udpated -->
		<Text>This is an Example </Text> <!-- This needs to be deleted -->
		<Text>This is an Example </Text> <!-- This needs to be deleted -->
		<Text>This is an Example </Text> <!-- This needs to be deleted -->
	</Task>
	<Task>
		<Text>This is an Example </Text>  <!-- value of this needs to be udpated -->
		<Text>This is an Example </Text> <!-- This needs to be deleted -->
		<Text>This is an Example </Text> <!-- This needs to be deleted -->
		<Text>This is an Example </Text> <!-- This needs to be deleted -->
		<Text>This is an Example </Text> <!-- This needs to be deleted -->
	</Task>
	<Task>
		<Text>This is an Example </Text> <!-- value of this needs to be udpated -->
	</Task>	
</Document>

Any help is appreciated… thanks


#2

@hangon

After lots of struggle i have found the way to do this within existing UiPath activities. My core idea has been derived from the below code snippet.

XDocument doc = XDocument.Load(“FileName.xml”);
XElement element = doc.Descendants(“Order”).Where(arg => arg.Attribute(“Id”).Value == “jason”) .Single();

element.Attribute(“Quantity”).Value = “3”;
doc.Save(“FileName.xml”)

I have converted the above logic into UiPath it starts working :slight_smile:

XDocumentSteps

=====================================================

Try this and let me know if you need any help.