@Spellman.Lau ,Welcome to Microsoft Q&A, you could try to use XDocument to change caption attribute of the node.
Here is a code example you could refer to.
XDocument doc = XDocument.Load("test.xml");
var result = doc.Descendants("text").Where(i => i.Attributes().Select(m => m.Value.ToString()).FirstOrDefault().Contains("TextNo"));
int n = 1;
foreach (var item in result)
{
item.Attribute("caption").Value = n.ToString();
n++;
}
doc.Save("test.xml");
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our [documentation][3] to enable e-mail notifications if you want to receive the related email notification for this thread.