Locate and insert new value
-
Hi all,
I need a big help to locate and insert value operation in np++
Below you can see the required part from XML file. I need to locate <t_to> then <to_person> and insert <nationality1>US</nationality1> tag below the <ssn>
tag.
<t_to>
<to_funds_code>CASH</to_funds_code>
<to_person>
<first_name>ANTHONAN BETHO PERERA</first_name>
<last_name>GOTHEN</last_name>
<ssn>6115456465465A</ssn>
nationality1>US</nationality1>
</to_person>
<to_country>FR</to_country>
</t_to> -
Using the technique shown HERE, this seems to do it:
find:
(?s-i:<t_to>.*?<to_person>|(?!\A)\G)(?s:(?!</to_person>.*?</t_to>).)*?\K(?-i:</last_name>\R)
repl:$0<ssn>6115456465465A</ssn>\r\n
mode: Regular expression -
Hello, @gonka-weerakoon, @alan-kilborn and All,
@alan-kilborn, I"m surprised and don’t understand your regex replacement ! Perhaps, I’m missing something obvious !
@gonka-weerakoon, if all your sections, below, contains
<ssn>xxxxxxxxxxxx</ssn>matchings tags :<t_to> ... <to_person> ... ... <ssn>6115456465465A</ssn> </to_person> ... </t_to>Then :
-
Open the Replace dialog (
Ctrl + H) -
SEARCH
(?s-i)<t_to>.*?<to_person>.*?</ssn>\R\K -
REPLACE
nationality1>US</nationality1>\r\n -
Untick all options
-
Tick the
Wrap aroundoption -
Select the
Regular expressionsearch mode -
Click once on the
Replace Allbutton ( do not use the Replace button ! )
In case that some sections
<t_to>............</t_to>do not contain a<ssn>xxxxxxxxxxxx</ssn>part, just tell me in order to modify the search regex accordingly !Best Regards,
guy038
-
-
@guy038 said in Locate and insert new value:
I"m surprised and don’t understand your regex replacement
I don’t understand it now either.
For some reason I thought OP wanted to insert the ssn tag and value!
Oops.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login