Generate loops in xml templats
-
Hi
I want to make a loop in a given template, where I wich to insert a value in the same line, and it must be replaced with value from a txt or excel continuouslyI have not yet been able to find solution so therefore my question, and hope for some help to solve that issue
Example
I have an xml template which I’ve made several times via Macro, and I want to continuously replace [A] in this line <userId> [A] </userId> with a list in a txt or excel (A,B and C)<userId>[A]</userId>
<criteriaName></criteriaName>
<fromDnCriteria>
<fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection>
<includeAnonymousCallers>false</includeAnonymousCallers>
<includeUnavailableCallers>false</includeUnavailableCallers><userId>[B]</userId> <criteriaName></criteriaName> <fromDnCriteria> <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> <includeAnonymousCallers>false</includeAnonymousCallers> <includeUnavailableCallers>false</includeUnavailableCallers> <userId>[C]</userId> <criteriaName></criteriaName> <fromDnCriteria> <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> <includeAnonymousCallers>false</includeAnonymousCallers> <includeUnavailableCallers>false</includeUnavailableCallers>
Br
Per Elkjær -
Hello, @per-elkjær-nielsen, and All,
Not difficult with regular expressions, indeed !
Let’s suppose that you have this list of
user-id
, below :569AB56AZ 123CD12AY 89CD1HJ 9999AZ0000AR 1AA52ZZ
Just note that the lines, above, may contain any kind of
user-id
!Then :
-
Open a new N++ tab
-
Paste your complete list of
user-id
items -
Add a separator line of, EXACTLY ,
5
tildes -
Now, add your xml template, WITHOUT the first line
<userId>.....</userId>
-
Finally, add a last line-break, after the last line
<includeUnavailableCallers>false</includeUnavailableCallers>
So, refering to our example, we get the following text :
569AB56AZ 123CD12AY 89CD1HJ 9999AZ0000AR 1AA52ZZ ~~~~~ <criteriaName></criteriaName> <fromDnCriteria> <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> <includeAnonymousCallers>false</includeAnonymousCallers> <includeUnavailableCallers>false</includeUnavailableCallers>
Then :
-
Open the Replace dialog (
Ctrl + H
) -
SEARCH
(?-s)^(.+)(?s)(?=.+^~~~~~(\R.+))|^~~~~~.+
-
REPLACE
?1\x20\x20\x20\x20\x20<userId>\1</userId>\2
-
Check, preferably, the
Wrap around
option -
Select the
Regular expression
search mode -
Click once, on the
Replace All
or several times on theReplace
button
Et voilà !
You text should have been changed into :
<userId>569AB56AZ</userId> <criteriaName></criteriaName> <fromDnCriteria> <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> <includeAnonymousCallers>false</includeAnonymousCallers> <includeUnavailableCallers>false</includeUnavailableCallers> <userId>123CD12AY</userId> <criteriaName></criteriaName> <fromDnCriteria> <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> <includeAnonymousCallers>false</includeAnonymousCallers> <includeUnavailableCallers>false</includeUnavailableCallers> <userId>89CD1HJ</userId> <criteriaName></criteriaName> <fromDnCriteria> <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> <includeAnonymousCallers>false</includeAnonymousCallers> <includeUnavailableCallers>false</includeUnavailableCallers> <userId>9999AZ0000AR</userId> <criteriaName></criteriaName> <fromDnCriteria> <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> <includeAnonymousCallers>false</includeAnonymousCallers> <includeUnavailableCallers>false</includeUnavailableCallers> <userId>1AA52ZZ</userId> <criteriaName></criteriaName> <fromDnCriteria> <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> <includeAnonymousCallers>false</includeAnonymousCallers> <includeUnavailableCallers>false</includeUnavailableCallers>
Nice, isn’t it ?
Remarks :
-
If the last line of your template, ending the current file, is not followed with a line-break, then, after replacement, the different blocks are joined and not separated with an empty line
-
I’ve respected the number of leadings spaces (
5
), of the line<userId>..........</userId>
. If necessary, adjust the number of\x20
, in the replacement part !
Best Regards,
guy038
-
-
Great :-) that’s working as you said :-)
If now <userId></userId> not is the first line,but the second line , what would then ?1\x20\x20\x20\x20\x20<userId>\1</userId>\2 be
Forgive my questions, I’m not so familiar with regular expressions yet :-)
Example:
<fromDnCriteria>
<userId></userId>
<criteriaName></criteriaName>
<fromDnCriteria>
<fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection>
<includeAnonymousCallers>false</includeAnonymousCallers>
<includeUnavailableCallers>false</includeUnavailableCallers>Br Per
-
Hi, @per-elkjær-nielsen,
The possible lines, located before the
<userId>..........</userId>
part is not the problem. As usual, I only need to know the general layout of the text, on which the regex will act !Furthermore, in your last example, there are two lines
<fromDnCriteria>
One of the two shouldn’t it be</fromDnCriteria>
?Here are the way how I imagine your text, with, of course, the different user-id instead of the
■
characters :... <fromDnCriteria> <userId>■</userId> <criteriaName></criteriaName> </fromDnCriteria> <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> <includeAnonymousCallers>false</includeAnonymousCallers> <includeUnavailableCallers>false</includeUnavailableCallers> <fromDnCriteria> <userId>■</userId> <criteriaName></criteriaName> </fromDnCriteria> <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> <includeAnonymousCallers>false</includeAnonymousCallers> <includeUnavailableCallers>false</includeUnavailableCallers> ....
Just tell me if I’m right or wrong about it ! Remember that regexes are very sensitive to real text : a simple space char or an additional line-break can cause the regular expression to malfunction
So, I would advice to put some part of
XML
code, as it is, without any additional indentation, between the following two lines :~~~xml
~~~
See you later,
BR
guy038
-
Hi guy038
The example should simply illustrate a given xml file where I want to change a value in a different line than the first line so that it is correctly illustrated
My plan was to be able to find a regular expressions template which I just have to adjust depending on which line I want to insert a value with loop
Example of real xml template I will typically work with:
<?xml version=“1.0” encoding=“ISO-8859-1”?>
<BroadsoftDocument protocol=“OCI” xmlns=“C”>
<sessionId xmlns=“”></sessionId>
<command xsi:type=“UserSelectiveCallRejectionAddCriteriaRequest16” xmlns=“” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”>
<userId></userId>
<criteriaName></criteriaName>
<fromDnCriteria>
<fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection>
<includeAnonymousCallers>false</includeAnonymousCallers>
<includeUnavailableCallers>false</includeUnavailableCallers>
<phoneNumber></phoneNumber>
</fromDnCriteria>
<blacklisted>false</blacklisted>
</command>
</BroadsoftDocument>And again <userId></userId> is my target
Br Per
-
Hi, @per-elkjær-nielsen and All,
Last night, when I was thinking about your problem, I discovered a fairly simple way to fill up data, in some areas of an
XML
template, simultaneously, thanks to the use of native N++ features such as column editor, sorting and regular expressions !I was quite happy with my solution and eager to share it with you, but as it was getting late, I preferred to wait until the next day to reply you.
Unfortunately, today, I don’t really have a heart to laugh about and I’m just sick and sad about what just happened in New Zealand:-((( We have already experienced such horrors in France. These terrorists, whatever their politic opinions, are an insult to human intelligence ! When will this murderous madness end ?
Finally, when I see my pussy, coming and going over my keyboard, I just think she’s the most human of us ! But we will not abdicate and continue to enlighten consciences rather than compel them ! So, at my humble level, Per, I’m going to start by solving your problem ! The method is a bit long, but works nicely ;-))
Let’s suppose we have this
XML
template, repeated12
times, consecutively, in a new tab :<command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <userId></userId> <criteriaName></criteriaName> <fromDnCriteria> <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> <includeAnonymousCallers>false</includeAnonymousCallers> <includeUnavailableCallers>false</includeUnavailableCallers> <phoneNumber></phoneNumber> </fromDnCriteria> <blacklisted>false</blacklisted> </command> <command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <userId></userId> <criteriaName></criteriaName> <fromDnCriteria> <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> <includeAnonymousCallers>false</includeAnonymousCallers> <includeUnavailableCallers>false</includeUnavailableCallers> <phoneNumber></phoneNumber> </fromDnCriteria> <blacklisted>false</blacklisted> </command> <command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <userId></userId> <criteriaName></criteriaName> .............. ..............
Here, I 've just showed two identical templates, as a post cannot contain more than
16384
chars ! But just imagine there are12
, in totality !Now :
-
Move the cursor at the very beginning of text
-
Open the Column editor (
Alt + C
orEditor > Column Editor...
) -
Select the option
Number to Insert
-
Type
1
as Initial number -
Type
1
as Increase by -
Type
11
as Repeat ( Note that it’s the exact number of lines of the template ! ) -
Check the
Leading zeros
option ( IMPORTANT ) -
Verify that the
Dec
format is selected -
Click on the
OK
button
Once, you’ve get rid of the unnecessary number(s), on the empty lines, at the very end, You should get something like below :
01<command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 01 <userId></userId> 01 <criteriaName></criteriaName> 01 <fromDnCriteria> 01 <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> 01 <includeAnonymousCallers>false</includeAnonymousCallers> 01 <includeUnavailableCallers>false</includeUnavailableCallers> 01 <phoneNumber></phoneNumber> 01 </fromDnCriteria> 01 <blacklisted>false</blacklisted> 01</command> 02<command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 02 <userId></userId> 02 <criteriaName></criteriaName> 02 <fromDnCriteria> .......... .......... 11 </fromDnCriteria> 11 <blacklisted>false</blacklisted> 11</command> 12<command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 12 <userId></userId> 12 <criteriaName></criteriaName> 12 <fromDnCriteria> 12 <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> 12 <includeAnonymousCallers>false</includeAnonymousCallers> 12 <includeUnavailableCallers>false</includeUnavailableCallers> 12 <phoneNumber></phoneNumber> 12 </fromDnCriteria> 12 <blacklisted>false</blacklisted> 12</command>
Then,
-
Move back, again, to the first line of text (
01<command xsi....
) -
Place the cursor between
01
and<command xsi....
( IMPORTANT ) -
Open, again, the Column editor (
Alt + C
orEditor > Column Editor...
) -
Select the option
Number to Insert
-
Type
1
as Initial number -
Type
1
as Increase by -
Type
1
as Repeat -
Check the
Leading zeros
option ( IMPORTANT ) -
Verify that the
Dec
format is selected -
Click on the
OK
button
This time, we get the following text :
01001<command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 01002 <userId></userId> 01003 <criteriaName></criteriaName> 01004 <fromDnCriteria> 01005 <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> 01006 <includeAnonymousCallers>false</includeAnonymousCallers> 01007 <includeUnavailableCallers>false</includeUnavailableCallers> 01008 <phoneNumber></phoneNumber> 01009 </fromDnCriteria> 01010 <blacklisted>false</blacklisted> 01011</command> 02012<command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 02013 <userId></userId> 02014 <criteriaName></criteriaName> 02015 <fromDnCriteria> .......... .......... 11119 </fromDnCriteria> 11120 <blacklisted>false</blacklisted> 11121</command> 12122<command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 12123 <userId></userId> 12124 <criteriaName></criteriaName> 12125 <fromDnCriteria> 12126 <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> 12127 <includeAnonymousCallers>false</includeAnonymousCallers> 12128 <includeUnavailableCallers>false</includeUnavailableCallers> 12129 <phoneNumber></phoneNumber> 12130 </fromDnCriteria> 12131 <blacklisted>false</blacklisted> 12132</command>
Quite logical : this second numbering reaches number
132
as it corresponds to the total of12
templates of11
lines !
Now, let’s suppose that we would like to fill up, simultaneously, in the
XML
templates, these 3XML
following elements :<userId></userId>
<criteriaName></criteriaName>
<phoneNumber></phoneNumber>
with
12
values, stored in3
text files. For instance, let’s suppose that :- The user-Id values are :
569AB56AZ 123CD12AY 89CD1HJ 9999AZ0000AR 1AA52ZZ 956AH45 ZZA125G 0000000000 999 AAAAAAA ZZZZZZZ ABCDE
- The criteriaName values are :
ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE TEN ELEVEN TWELVE
- The phoneNumber values are :
01 23 45 67 89 99 98 97 96 95 00 01 02 03 04 99 00 99 00 99 00 00 11 11 22 11 22 33 44 55 66 77 88 99 00 98 76 54 32 10 00 00 01 11 11 99 00 88 11 77 66 22 55 33 44 99 99 99 00 00
Then , number the lines of these
3
lists of data, at column1
, using the previous classical numbering and, then, gather these values in a single block, as below :01569AB56AZ 02123CD12AY 0389CD1HJ 049999AZ0000AR 051AA52ZZ 06956AH45 07ZZA125G 080000000000 09999 10AAAAAAA 11ZZZZZZZ 12ABCDE 01ONE 02TWO 03THREE 04FOUR 05FIVE 06SIX 07SEVEN 08EIGHT 09NINE 10TEN 11ELEVEN 12TWELVE 0101 23 45 67 89 0299 98 97 96 95 0300 01 02 03 04 0499 00 99 00 99 0500 00 11 11 22 0611 22 33 44 55 0766 77 88 99 00 0898 76 54 32 10 0900 00 01 11 11 1099 00 88 11 77 1166 22 55 33 44 1299 99 99 00 00
Now, in addition to this
2
digits numbering, we’re going to choose a symbol, with Unicode code> \x39
, for each type of data and insert it, right after the numbering. I chose, randomly, the:
,=
and@
symbols. In order to line up with the resulting numbering of the templates, above, we’ll repeat each symbol,3
times. So, we get :01:::569AB56AZ 02:::123CD12AY 03:::89CD1HJ 04:::9999AZ0000AR 05:::1AA52ZZ 06:::956AH45 07:::ZZA125G 08:::0000000000 09:::999 10:::AAAAAAA 11:::ZZZZZZZ 12:::ABCDE 01===ONE 02===TWO 03===THREE 04===FOUR 05===FIVE 06===SIX 07===SEVEN 08===EIGHT 09===NINE 10===TEN 11===ELEVEN 12===TWELVE 01@@@01 23 45 67 89 02@@@99 98 97 96 95 03@@@00 01 02 03 04 04@@@99 00 99 00 99 05@@@00 00 11 11 22 06@@@11 22 33 44 55 07@@@66 77 88 99 00 08@@@98 76 54 32 10 09@@@00 00 01 11 11 10@@@99 00 88 11 77 11@@@66 22 55 33 44 12@@@99 99 99 00 00
Finally, let’s paste that global list, at the end of the new tab, after the
12
copies of your template.We obtain :
01001<command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 01002 <userId></userId> 01003 <criteriaName></criteriaName> 01004 <fromDnCriteria> 01005 <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> 01006 <includeAnonymousCallers>false</includeAnonymousCallers> 01007 <includeUnavailableCallers>false</includeUnavailableCallers> 01008 <phoneNumber></phoneNumber> 01009 </fromDnCriteria> 01010 <blacklisted>false</blacklisted> 01011</command> 02012<command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 02013 <userId></userId> 02014 <criteriaName></criteriaName> 02015 <fromDnCriteria> .......... .......... 11119 </fromDnCriteria> 11120 <blacklisted>false</blacklisted> 11121</command> 12122<command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 12123 <userId></userId> 12124 <criteriaName></criteriaName> 12125 <fromDnCriteria> 12126 <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> 12127 <includeAnonymousCallers>false</includeAnonymousCallers> 12128 <includeUnavailableCallers>false</includeUnavailableCallers> 12129 <phoneNumber></phoneNumber> 12130 </fromDnCriteria> 12131 <blacklisted>false</blacklisted> 12132</command> 01:::569AB56AZ 02:::123CD12AY 03:::89CD1HJ 04:::9999AZ0000AR 05:::1AA52ZZ 06:::956AH45 07:::ZZA125G 08:::0000000000 09:::999 10:::AAAAAAA 11:::ZZZZZZZ 12:::ABCDE 01===ONE 02===TWO 03===THREE 04===FOUR 05===FIVE 06===SIX 07===SEVEN 08===EIGHT 09===NINE 10===TEN 11===ELEVEN 12===TWELVE 01@@@01 23 45 67 89 02@@@99 98 97 96 95 03@@@00 01 02 03 04 04@@@99 00 99 00 99 05@@@00 00 11 11 22 06@@@11 22 33 44 55 07@@@66 77 88 99 00 08@@@98 76 54 32 10 09@@@00 00 01 11 11 10@@@99 00 88 11 77 11@@@66 22 55 33 44 12@@@99 99 99 00 00
Now :
-
Perform a classical sort with the option
Edit > Line Operations > Sort lines Lexicographically Ascending
-
Add an empty line-break, at the end of the sorted text ( IMPORTANT )
Text should be, now, changed, as below :
01001<command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 01002 <userId></userId> 01003 <criteriaName></criteriaName> 01004 <fromDnCriteria> 01005 <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> 01006 <includeAnonymousCallers>false</includeAnonymousCallers> 01007 <includeUnavailableCallers>false</includeUnavailableCallers> 01008 <phoneNumber></phoneNumber> 01009 </fromDnCriteria> 01010 <blacklisted>false</blacklisted> 01011</command> 01:::569AB56AZ 01===ONE 01@@@01 23 45 67 89 02012<command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 02013 <userId></userId> 02014 <criteriaName></criteriaName> 02015 <fromDnCriteria> 02016 <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> 02017 <includeAnonymousCallers>false</includeAnonymousCallers> 02018 <includeUnavailableCallers>false</includeUnavailableCallers> 02019 <phoneNumber></phoneNumber> 02020 </fromDnCriteria> 02021 <blacklisted>false</blacklisted> 02022</command> 02:::123CD12AY 02===TWO 02@@@99 98 97 96 95 03023<command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 03024 <userId></userId> 03025 <criteriaName></criteriaName> .......... .......... 11118 <phoneNumber></phoneNumber> 11119 </fromDnCriteria> 11120 <blacklisted>false</blacklisted> 11121</command> 11:::ZZZZZZZ 11===ELEVEN 11@@@66 22 55 33 44 12122<command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 12123 <userId></userId> 12124 <criteriaName></criteriaName> 12125 <fromDnCriteria> 12126 <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> 12127 <includeAnonymousCallers>false</includeAnonymousCallers> 12128 <includeUnavailableCallers>false</includeUnavailableCallers> 12129 <phoneNumber></phoneNumber> 12130 </fromDnCriteria> 12131 <blacklisted>false</blacklisted> 12132</command> 12:::ABCDE 12===TWELVE 12@@@99 99 99 00 00
Sorry, the rest in the following post !
-
-
Hi, all,
This method is almost finished ! Now, we’re going to fill up the different
XML
elements, with their respective values, using the generic regex S/R, below :SEARCH
(?-s)^\d+.*<(
TAG)>(?=</\1>(.|\R)+?^\d+
Symbol+(.+)\R)|^\d+
Symbol+(.+)\R
REPLACE
?1$0\3
Where :
-
TAG =
userId
orcriteriaName
orphoneNumber
-
Symbol =
:
or=
or@
This leads to the
3
correct search regexes :- SEARCH
(?-s)^\d+.*<(userId)>(?=</\1>(.|\R)+?^\d+:+(.+)\R)|^\d+:+(.+)\R
- SEARCH
(?-s)^\d+.*<(criteriaName)>(?=</\1>(.|\R)+?^\d+=+(.+)\R)|^\d+=+(.+)\R
- SEARCH
(?-s)^\d+.*<(phoneNumber)>(?=</\1>(.|\R)+?^\d+@+(.+)\R)|^\d+@+(.+)\R
with the unique replacement
- REPLACE
?1$0\3
After running, successively, these
3
S/R (24
occurrences replaced for each ), we almost get your final text :01001<command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 01002 <userId>569AB56AZ</userId> 01003 <criteriaName>ONE</criteriaName> 01004 <fromDnCriteria> 01005 <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> 01006 <includeAnonymousCallers>false</includeAnonymousCallers> 01007 <includeUnavailableCallers>false</includeUnavailableCallers> 01008 <phoneNumber>01 23 45 67 89</phoneNumber> 01009 </fromDnCriteria> 01010 <blacklisted>false</blacklisted> 01011</command> 02012<command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 02013 <userId>123CD12AY</userId> 02014 <criteriaName>TWO</criteriaName> 02015 <fromDnCriteria> 02016 <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> 02017 <includeAnonymousCallers>false</includeAnonymousCallers> 02018 <includeUnavailableCallers>false</includeUnavailableCallers> 02019 <phoneNumber>99 98 97 96 95</phoneNumber> 02020 </fromDnCriteria> 02021 <blacklisted>false</blacklisted> 02022</command> 03023<command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 03024 <userId>89CD1HJ</userId> 03025 <criteriaName>THREE</criteriaName> .......... .......... 11117 <includeUnavailableCallers>false</includeUnavailableCallers> 11118 <phoneNumber>66 22 55 33 44</phoneNumber> 11119 </fromDnCriteria> 11120 <blacklisted>false</blacklisted> 11121</command> 12122<command xsi:type="UserSelectiveCallRejectionAddCriteriaRequest16" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 12123 <userId>ABCDE</userId> 12124 <criteriaName>TWELVE</criteriaName> 12125 <fromDnCriteria> 12126 <fromDnCriteriaSelection>Specified Only</fromDnCriteriaSelection> 12127 <includeAnonymousCallers>false</includeAnonymousCallers> 12128 <includeUnavailableCallers>false</includeUnavailableCallers> 12129 <phoneNumber>99 99 99 00 00</phoneNumber> 12130 </fromDnCriteria> 12131 <blacklisted>false</blacklisted> 12132</command>
Notes :
-
That generic regex has two alternatives :
-
^\d+.*<(
TAG)>(?=</\1>(.|\R)+?(^\d+
Symbol+(.+)\R)
, which looks for text from beginning of current line till the opening TAG, stored as group1
, only if the line^\d+
Symbol+(.+)\R
can be found, further on -
^\d+
Symbol+(.+)\R
, which searches any complete line, containing the symbols (:
,=
or@
) and the different values
-
-
In replacement, we just add the appropriate value (
\3
), to the currentXML
element ($0
), only if group1
exits (?1
). When the second alternative is found, it’s just deleted because group1
does not exist !
To end, we just have to get rid of the
5
digits, at beginning of all the lines, which can be easily achieved with the regex S/R :SEARCH
^\d{5}
REPLACE
Leave EMPTY
Remark :
-
I’m pretty confident about the generic regex S/R, for, at least, two reasons :
-
Due to the sort operation, the different values, to insert in the
XML
document, are moved at the end of each template Thus , they are not very far from the location where they should end ! -
I tested with a
XML
template of more than400
lines, repeated5
times, without any problem, For instance, there was more than23,500
characters between the first<userId>.....</userId>
block and the line1:::::569AB56AZ
containing the value to insert after<user>
. However, the regex correctly associates the tag<userId>
to its respective value569AB56AZ
, thanks to the look-ahead feature !
-
Best Regards
guy038
-
-
Hi guy038
It’s a very impressive workaround you’ve come to. It’s not easy on , but it works for purposes I wanted
At the same time, it has been very helpfull to follow your guides on using Regex, Which inspire me to try on my own to create simelar xml templates
Many thanks and sorry the long response time
Br Per