0

I have hundreds of xml files that have different types of IDs e.g. submitter, requester, agent etc. I want to do a find/replace just the value for the Requester ID. XML is displayed thus:

<Submitter>
    <ID>1578642S</ID>
</Submitter>

<Requester>
    <ID>1748791R</ID>
</Requester>

<Agent>
    <ID>198791A</ID>
</Agent>

2 Answers 2

2

Find:

<Requester>\s*<ID>\w+</ID>\s*</Requester>

Replace:

<Requester>\n<ID>newID</ID>\n</Requester>
2
  • Thanks very much for your help.
    – ratsstack
    Commented Oct 6, 2015 at 2:18
  • I expanded what you had a bit further to retain format in the XML: <Requester>\n\t\t<ID>newID</ID>\n\t</Requester>
    – ratsstack
    Commented Oct 6, 2015 at 2:19
0

This sounds like a task for xpath, not for regex or find-replace. Since you are navigating an xml to find a particular tag and replace it's text value, not finding a text pattern. an xpath code like

'//Requester/ID/*' 

should get you all instances of Requester/ID in your XML... you'll just need to wrap it in a script (of your prefered language) to iterate over the documents and replace the values and you'll be done in no time.

Not the answer you're looking for? Browse other questions tagged or ask your own question.