Editing attributes in XML file

Hi,
I need help in editing attributes in XML files. I have an XML file (sample shown below)

<REQUEST_GROUP ABCDEVersionID=“2.3.1”>
<REQUESTING_PARTY _Name=“ABCD Integration Services” _StreetAddress=“270 EAST WEST AVE” _StreetAddress2="" _City=“MILWAUKEE” _State=“WI” _PostalCode=“53202” _Identifier=“ABC1200B5X”>
<CONTACT_DETAIL _Name=“Lynnanne Huber”>
<CONTACT_POINT _RoleType=“Work” _Type=“Phone” _Value=""></CONTACT_POINT>
<CONTACT_POINT _RoleType=“Work” _Type=“Email” _Value="test_email@abcd.com"></CONTACT_POINT>
</CONTACT_DETAIL>
<PREFERRED_RESPONSE _Format=“PDF” _Method=“File” _UseEmbeddedFileIndicator=“Y”></PREFERRED_RESPONSE>
</REQUESTING_PARTY>

In the data above i want to replace/edit text in attribute field like “_RoleType”, “_Type” in XPath <Contact_Point>, but I am able to change the data in first one only not in the second once as both are same.
Kindly suggest how can I change it in both the Xpaths.

@Priyansh_Varshney
Welcome to the forum

We can do it as following:


xeCPEmail.Attribute("_Value").Value = “abc@domain.com

Alternate:
import following to the namespace
grafik

Access the Element by XPATH
grafik

And edit the value as done above.

1 Like

Thanks @ppr,
This was really helpful!!

Adding further to this what should be done if we have below XML where we have multiple Parent nodes with same name (REQUESTING_PARTY) like below,

<REQUEST_GROUP ABCDEVersionID=“2.3.1”>

<REQUESTING_PARTY _Name=“ABCD Integration Services” _StreetAddress=“270 EAST WEST AVE” _StreetAddress2="" _City=“MILWAUKEE” _State=“WI” _PostalCode=“53202” _Identifier=“ABC1200B5X”>
<CONTACT_DETAIL _Name=“Lynnanne Huber”>
<CONTACT_POINT _RoleType=“Work” _Type=“Phone” _Value=""></CONTACT_POINT>
<CONTACT_POINT _RoleType=“Work” _Type=“Email” _Value="test_email@abcd.com"></CONTACT_POINT>
</CONTACT_DETAIL>
<PREFERRED_RESPONSE _Format=“PDF” _Method=“File” _UseEmbeddedFileIndicator=“Y”></PREFERRED_RESPONSE>
</REQUESTING_PARTY>

<RECEIVING_PARTY _Name=“Testing”>Found</RECEIVING_PARTY>
<SUBMITTING_PARTY _Name=“Testing”>

<MI_APPLICATION MISMOVersionID=“2.3.1”>
<REQUESTING_PARTY _Name=“ABCD Integration Services” _StreetAddress=“270 EAST WEST AVE” _StreetAddress2="" _City=“MILWAUKEE” _State=“WI” _PostalCode=“53202” _Identifier=“ABC1200B5X”>
<CONTACT_DETAIL _Name=“Lynnanne Huber”>
<CONTACT_POINT _RoleType=“Work” _Type=“Phone” _Value=""></CONTACT_POINT>
<CONTACT_POINT _RoleType=“Work” _Type=“Email” _Value="test_email@abcd.com"></CONTACT_POINT>
</CONTACT_DETAIL>
<PREFERRED_RESPONSE _Format=“PDF” _Method=“File” _UseEmbeddedFileIndicator=“Y”></PREFERRED_RESPONSE>
</REQUESTING_PARTY>
</MI_APPLICATION>

as here we are able to change the value of the first one only.

@Priyansh_Varshney

xDoc.Root.Descendants(“CONTACT_POINT”).Where(Function (x) x.Attribute("_Type").Value.Equals(“Email”)).First()

Descendants… retrurns all found CONTACT_POINT as filtered within the Where block
used .First() on end will resturn the first item.

So it is already done with this statement

also feel free to browse following list for samples:
https://forum.uipath.com/search?q=@ppr%20XML

@ppr
What should be the Variable Type for xeCPEmail here? I am getting this error on Assign,

please share the detailed texts / statements from the assign activity
and details from the variable panel
Thanks

it looks like you ommited the First() statement when initializing xeCPEmail
And xeCPEmail is not of Datatype XElement.
Just relook on demo xaml, as it is already implemented and running

@ppr

Let me show you what is happening right now. Below is the snip of XML I am using and I need to change the _Value for _Type="Email" Marked in Point-1 and Point-2. But when I use the suggested code above it replaces only for Point-1 as obviously we are using .first()

So the issue I am facing is how to change both.
XML before:

XML After:

Process Snip:

Below will iterate over all Contact_Point with atribute _Type is email elements
grafik
Set for each typeargument to XElement

Or as an alternate with a XPATH (kindly note the s in SelectElements)
grafik

giving me error:

just debug it to find out what is happening, as it was working on my end successfully
working with the immediate panel is very helpfully for such analyzes
give a try with the other statement as well

Hi @ppr,

Thank you so much for all the help, It worked for me when I redid it in a new process. This small piece of thing was blocking my whole process, and just because of you I am able to complete this. Really appreciate you help!!

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