Batch - For and Findstr with multiple criteria printed on same line - api

I am trying to parse some xml files and extract some data. The data pertains to the Magic The Gathering card game card data from an API. The results when I search for a card (Goblin Warchief in this example) look like this:
<?xml version="1.0" encoding="utf-8"?>
<response>
<product>
<idProduct>1090</idProduct>
<idMetaproduct>2459</idMetaproduct>
<countReprints>8</countReprints>
<enName>Goblin Warchief</enName>
<locName>Goblin Warchief</locName>
<localization>
<name>Goblin Warchief</name>
<idLanguage>1</idLanguage>
<languageName>English</languageName>
</localization>
<localization>
<name>Chef de guerre gobelin</name>
<idLanguage>2</idLanguage>
<languageName>French</languageName>
</localization>
<localization>
<name>Goblin-Kriegsh„uptling</name>
<idLanguage>3</idLanguage>
<languageName>German</languageName>
</localization>
<localization>
<name>Jefe de guerra trasgo</name>
<idLanguage>4</idLanguage>
<languageName>Spanish</languageName>
</localization>
<localization>
<name>Condottiero Goblin</name>
<idLanguage>5</idLanguage>
<languageName>Italian</languageName>
</localization>
<website>/en/Magic/Products/Singles/Scourge/Goblin-Warchief</website>
<image>./img/items/1/SCG/1090.jpg</image>
<gameName>Magic the Gathering</gameName>
<categoryName>Magic Single</categoryName>
<idGame>1</idGame>
<number>97</number>
<rarity>Uncommon</rarity>
<expansionName>Scourge</expansionName>
<expansionIcon>41</expansionIcon>
<countArticles>1524</countArticles>
<countFoils>41</countFoils>
<links>
<rel>product</rel>
<href>/products/1090</href>
<method>GET</method>
</links>
</product>
<product>
<idProduct>15846</idProduct>
<idMetaproduct>2459</idMetaproduct>
<countReprints>8</countReprints>
<enName>Goblin Warchief (Version 1)</enName>
<locName>Goblin Warchief (Version 1)</locName>
<localization>
<name>Goblin Warchief</name>
<idLanguage>1</idLanguage>
<languageName>English</languageName>
</localization>
<localization>
<name>Chef de guerre gobelin</name>
<idLanguage>2</idLanguage>
<languageName>French</languageName>
</localization>
<localization>
<name>Goblin-Kriegsh„uptling</name>
<idLanguage>3</idLanguage>
<languageName>German</languageName>
</localization>
<localization>
<name>Jefe de guerra trasgo</name>
<idLanguage>4</idLanguage>
<languageName>Spanish</languageName>
</localization>
<localization>
<name>Condottiero Goblin</name>
<idLanguage>5</idLanguage>
<languageName>Italian</languageName>
</localization>
<website>/en/Magic/Products/Singles/Friday+Night+Magic+Promos/Goblin-Warchief-Version-1</website>
<image>./img/items/1/FNM/15846.jpg</image>
<gameName>Magic the Gathering</gameName>
<categoryName>Magic Single</categoryName>
<idGame>1</idGame>
<number>2006-05</number>
<rarity>Rare</rarity>
<expansionName>Friday Night Magic Promos</expansionName>
<expansionIcon>69</expansionIcon>
<countArticles>234</countArticles>
<countFoils>213</countFoils>
<links>
<rel>product</rel>
<href>/products/15846</href>
<method>GET</method>
</links>
</product>
<product>
<idProduct>288444</idProduct>
<idMetaproduct>2459</idMetaproduct>
<countReprints>8</countReprints>
<enName>Goblin Warchief (Version 2)</enName>
<locName>Goblin Warchief (Version 2)</locName>
<localization>
<name>Goblin Warchief</name>
<idLanguage>1</idLanguage>
<languageName>English</languageName>
</localization>
<localization>
<name>Chef de guerre gobelin</name>
<idLanguage>2</idLanguage>
<languageName>French</languageName>
</localization>
<localization>
<name>Goblin-Kriegsh„uptling</name>
<idLanguage>3</idLanguage>
<languageName>German</languageName>
</localization>
<localization>
<name>Jefe de guerra trasgo</name>
<idLanguage>4</idLanguage>
<languageName>Spanish</languageName>
</localization>
<localization>
<name>Condottiero Goblin</name>
<idLanguage>5</idLanguage>
<languageName>Italian</languageName>
</localization>
<website>/en/Magic/Products/Singles/Friday+Night+Magic+Promos/Goblin-Warchief-Version-2</website>
<image>./img/items/1/FNM/288444.jpg</image>
<gameName>Magic the Gathering</gameName>
<categoryName>Magic Single</categoryName>
<idGame>1</idGame>
<number>2016-05</number>
<rarity>Rare</rarity>
<expansionName>Friday Night Magic Promos</expansionName>
<expansionIcon>69</expansionIcon>
<countArticles>1425</countArticles>
<countFoils>1425</countFoils>
<links>
<rel>product</rel>
<href>/products/288444</href>
<method>GET</method>
</links>
</product>
<product>
<idProduct>18797</idProduct>
<idMetaproduct>2459</idMetaproduct>
<countReprints>8</countReprints>
<enName>Goblin Warchief</enName>
<locName>Goblin Warchief</locName>
<localization>
<name>Goblin Warchief</name>
<idLanguage>1</idLanguage>
<languageName>English</languageName>
</localization>
<localization>
<name>Chef de guerre gobelin</name>
<idLanguage>2</idLanguage>
<languageName>French</languageName>
</localization>
<localization>
<name>Goblin-Kriegsh„uptling</name>
<idLanguage>3</idLanguage>
<languageName>German</languageName>
</localization>
<localization>
<name>Jefe de guerra trasgo</name>
<idLanguage>4</idLanguage>
<languageName>Spanish</languageName>
</localization>
<localization>
<name>Condottiero Goblin</name>
<idLanguage>5</idLanguage>
<languageName>Italian</languageName>
</localization>
<website>/en/Magic/Products/Singles/Duel+Decks%3A+Elves+vs.+Goblins/Goblin-Warchief</website>
<image>./img/items/1/EVG/18797.jpg</image>
<gameName>Magic the Gathering</gameName>
<categoryName>Magic Single</categoryName>
<idGame>1</idGame>
<number>42</number>
<rarity>Uncommon</rarity>
<expansionName>Duel Decks: Elves vs. Goblins</expansionName>
<expansionIcon>88</expansionIcon>
<countArticles>254</countArticles>
<countFoils>0</countFoils>
<links>
<rel>product</rel>
<href>/products/18797</href>
<method>GET</method>
</links>
</product>
<product>
<idProduct>249281</idProduct>
<idMetaproduct>2459</idMetaproduct>
<countReprints>8</countReprints>
<enName>Goblin Warchief</enName>
<locName>Goblin Warchief</locName>
<localization>
<name>Goblin Warchief</name>
<idLanguage>1</idLanguage>
<languageName>English</languageName>
</localization>
<localization>
<name>Chef de guerre gobelin</name>
<idLanguage>2</idLanguage>
<languageName>French</languageName>
</localization>
<localization>
<name>Goblin-Kriegsh„uptling</name>
<idLanguage>3</idLanguage>
<languageName>German</languageName>
</localization>
<localization>
<name>Jefe de guerra trasgo</name>
<idLanguage>4</idLanguage>
<languageName>Spanish</languageName>
</localization>
<localization>
<name>Condottiero Goblin</name>
<idLanguage>5</idLanguage>
<languageName>Italian</languageName>
</localization>
<website>/en/Magic/Products/Singles/WCD+2003%3A+Wolfgang+Eder/Goblin-Warchief</website>
<image>./img/items/1/WCD34/249281.jpg</image>
<gameName>Magic the Gathering</gameName>
<categoryName>Magic Single</categoryName>
<idGame>1</idGame>
<number></number>
<rarity>Special</rarity>
<expansionName>WCD 2003: Wolfgang Eder</expansionName>
<expansionIcon>87</expansionIcon>
<countArticles>35</countArticles>
<countFoils>0</countFoils>
<links>
<rel>product</rel>
<href>/products/249281</href>
<method>GET</method>
</links>
</product>
<product>
<idProduct>268812</idProduct>
<idMetaproduct>2459</idMetaproduct>
<countReprints>8</countReprints>
<enName>Goblin Warchief</enName>
<locName>Goblin Warchief</locName>
<localization>
<name>Goblin Warchief</name>
<idLanguage>1</idLanguage>
<languageName>English</languageName>
</localization>
<localization>
<name>Chef de guerre gobelin</name>
<idLanguage>2</idLanguage>
<languageName>French</languageName>
</localization>
<localization>
<name>Goblin-Kriegsh„uptling</name>
<idLanguage>3</idLanguage>
<languageName>German</languageName>
</localization>
<localization>
<name>Jefe de guerra trasgo</name>
<idLanguage>4</idLanguage>
<languageName>Spanish</languageName>
</localization>
<localization>
<name>Condottiero Goblin</name>
<idLanguage>5</idLanguage>
<languageName>Italian</languageName>
</localization>
<website>/en/Magic/Products/Singles/Duel+Decks%3A+Speed+vs.+Cunning/Goblin-Warchief</website>
<image>./img/items/1/DDN/268812.jpg</image>
<gameName>Magic the Gathering</gameName>
<categoryName>Magic Single</categoryName>
<idGame>1</idGame>
<number>9</number>
<rarity>Uncommon</rarity>
<expansionName>Duel Decks: Speed vs. Cunning</expansionName>
<expansionIcon>256</expansionIcon>
<countArticles>1198</countArticles>
<countFoils>0</countFoils>
<links>
<rel>product</rel>
<href>/products/268812</href>
<method>GET</method>
</links>
</product>
<product>
<idProduct>270006</idProduct>
<idMetaproduct>2459</idMetaproduct>
<countReprints>8</countReprints>
<enName>Goblin Warchief</enName>
<locName>Goblin Warchief</locName>
<localization>
<name>Goblin Warchief</name>
<idLanguage>1</idLanguage>
<languageName>English</languageName>
</localization>
<localization>
<name>Chef de guerre gobelin</name>
<idLanguage>2</idLanguage>
<languageName>French</languageName>
</localization>
<localization>
<name>Goblin-Kriegsh„uptling</name>
<idLanguage>3</idLanguage>
<languageName>German</languageName>
</localization>
<localization>
<name>Jefe de guerra trasgo</name>
<idLanguage>4</idLanguage>
<languageName>Spanish</languageName>
</localization>
<localization>
<name>Condottiero Goblin</name>
<idLanguage>5</idLanguage>
<languageName>Italian</languageName>
</localization>
<website>/en/Magic/Products/Singles/Duel+Decks%3A+Anthology/Goblin-Warchief</website>
<image>./img/items/1/DD3/270006.jpg</image>
<gameName>Magic the Gathering</gameName>
<categoryName>Magic Single</categoryName>
<idGame>1</idGame>
<number>2042</number>
<rarity>Uncommon</rarity>
<expansionName>Duel Decks: Anthology</expansionName>
<expansionIcon>259</expansionIcon>
<countArticles>230</countArticles>
<countFoils>0</countFoils>
<links>
<rel>product</rel>
<href>/products/270006</href>
<method>GET</method>
</links>
</product>
<product>
<idProduct>319794</idProduct>
<idMetaproduct>2459</idMetaproduct>
<countReprints>8</countReprints>
<enName>Goblin Warchief</enName>
<locName>Goblin Warchief</locName>
<localization>
<name>Goblin Warchief</name>
<idLanguage>1</idLanguage>
<languageName>English</languageName>
</localization>
<localization>
<name>Chef de guerre gobelin</name>
<idLanguage>2</idLanguage>
<languageName>French</languageName>
</localization>
<localization>
<name>Goblin-Kriegsh„uptling</name>
<idLanguage>3</idLanguage>
<languageName>German</languageName>
</localization>
<localization>
<name>Jefe de guerra trasgo</name>
<idLanguage>4</idLanguage>
<languageName>Spanish</languageName>
</localization>
<localization>
<name>Condottiero Goblin</name>
<idLanguage>5</idLanguage>
<languageName>Italian</languageName>
</localization>
<website>/en/Magic/Products/Singles/Dominaria/Goblin-Warchief</website>
<image>./img/items/1/DOM/319794.jpg</image>
<gameName>Magic the Gathering</gameName>
<categoryName>Magic Single</categoryName>
<idGame>1</idGame>
<number>130</number>
<rarity>Uncommon</rarity>
<expansionName>Dominaria</expansionName>
<expansionIcon>419</expansionIcon>
<countArticles>7370</countArticles>
<countFoils>221</countFoils>
<links>
<rel>product</rel>
<href>/products/319794</href>
<method>GET</method>
</links>
</product>
<links>
<rel>self</rel>
<href>/products/find?search=Goblin%20Warchief&exact=true&idGame=1&idLanguage=1</href>
<method>GET</method>
</links>
</response>
So, as you can see, there are often multiple results for any given card search.
Now, what I am interested in doing is printing to a seperate file the and fields for each product, on the same line. So like this:
Goblin Warchief_Scourge
Goblin Warchief (Version 1)_Friday Night Magic Promos
Goblin Warchief (Version 2)_Friday Night Magic Promos
etc
I'd prefer to do this in batch, and the best I have managed to do so far is to simply print the enName and expansionName fields separately, with this:
#echo off
if exist searchResultFiltered.xml del searchResultFiltered.xml
rem The card name is passed in from the command line
set cardname=%~1
rem This uses an outside application to interface the API
mkm get "products/find?search=%cardname%&exact=true&idGame=1&idLanguage=1" > searchResult.xml
for /f "tokens=3 delims=<>" %%j in ('findstr "enName expansionName" "searchResult.xml"') do >> searchResultFiltered.xml echo %%j
This gives the output like this:
Goblin Warchief
Scourge
Goblin Warchief (Version 1)
Friday Night Magic Promos
Goblin Warchief (Version 2)
Friday Night Magic Promos
etc...
Can anyone help me get the line "pairs" onto the same line with a delimiter in-between please? I'd appreciate any help. I don't know if there's a way of doing it neatly with for and findstr, or if I need to print them to a new file or something.
Thanks!

set "flag="
for /f "tokens=3 delims=<>" %%j in ('findstr "enName expansionName" "searchResult.xml"') do (
if defined flag (
>> searchResultFiltered.xml call echo %%flag%% %%j&set "flag="
) else (set "flag=%%j")
)
flag is initialised to nothing.
The first item passing the findstr filter sees flag as not-defined, so sets (and hence defines) flag to the required text.
The next item through the gate now sees flag as defined hence echoes its value + the current line's value in a subshell; then clears flag.
Rinse and repeat.
For examples about the call echo %%var%% method to display the current value of var, see many articles on SO about delayed expansion.

Related

awk print lines until next match on the same line

I have the following type of data file:
0.033333 0.000000 0.000000
-46.956 -46.956 -23.678 -23.677 -23.055 -23.054 -22.974 -22.974 -8.033 -8.032
-7.375 -7.356 -7.182 -7.159 -6.695 -6.661 -6.628 -6.598 -4.477 -4.477
-4.470 -4.462 -4.387 -4.380 3.799 3.800 5.939 5.960 6.116 6.117
6.625 6.642 7.648 7.651 7.686 7.687 8.077 8.078 8.123 8.126
8.478 8.497 8.550 8.552 11.625 11.626 12.652 12.653 12.722 12.726
13.860 13.864 14.291 14.293 14.966 15.046 17.063 17.252 18.011 18.015
0.016667 0.000000 0.000000
-46.956 -46.956 -23.677 -23.677 -23.055 -23.054 -22.974 -22.974 -8.037 -8.036
-7.371 -7.361 -7.177 -7.165 -6.686 -6.669 -6.620 -6.605 -4.476 -4.475
-4.471 -4.465 -4.385 -4.382 3.811 3.812 5.942 5.952 6.115 6.115
6.629 6.638 7.651 7.653 7.688 7.689 8.072 8.073 8.122 8.123
8.491 8.501 8.556 8.556 11.612 11.612 12.665 12.665 12.730 12.733
13.835 13.837 14.288 14.289 14.991 15.031 17.132 17.225 18.053 18.055
0.000000 0.000000 0.000000
-46.956 -46.956 -23.677 -23.677 -23.055 -23.055 -22.974 -22.974 -8.038 -8.038
-7.366 -7.366 -7.172 -7.172 -6.678 -6.678 -6.613 -6.613 -4.475 -4.475
-4.469 -4.469 -4.384 -4.384 3.816 3.816 5.946 5.946 6.115 6.115
6.633 6.633 7.653 7.653 7.689 7.689 8.070 8.070 8.122 8.122
8.498 8.498 8.558 8.558 11.607 11.607 12.668 12.668 12.735 12.735
13.827 13.827 14.287 14.287 15.013 15.013 17.186 17.186 18.068 18.068
I need to change this to look like this:
0.033333 0.000000 0.000000 -46.956 -46.956 -23.678 -23.677 -23.055 -23.054 -22.974 -22.974 -8.033 -8.032 -7.375 -7.356 -7.182 -7.159 -6.695 -6.661 -6.628 -6.598 -4.477 -4.477 -4.470 -4.462 -4.387 -4.380 3.799 3.800 5.939 5.960 6.116 6.117 6.625 6.642 7.648 7.651 7.686 7.687 8.077 8.078 8.123 8.126 8.478 8.497 8.550 8.552 11.625 11.626 12.652 12.653 12.722 12.726 13.860 13.864 14.291 14.293 14.966 15.046 17.063 17.252 18.011 18.015
0.016667 0.000000 0.000000 -46.956 -46.956 -23.677 -23.677 -23.055 -23.054 -22.974 -22.974 -8.037 -8.036 -7.371 -7.361 -7.177 -7.165 -6.686 -6.669 -6.620 -6.605 -4.476 -4.475 -4.471 -4.465 -4.385 -4.382 3.811 3.812 5.942 5.952 6.115 6.115 6.629 6.638 7.651 7.653 7.688 7.689 8.072 8.073 8.122 8.123 8.491 8.501 8.556 8.556 11.612 11.612 12.665 12.665 12.730 12.733 13.835 13.837 14.288 14.289 14.991 15.031 17.132 17.225 18.053 18.055
0.000000 0.000000 0.000000 -46.956 -46.956 -23.677 -23.677 -23.055 -23.055 -22.974 -22.974 -8.038 -8.038 -7.366 -7.366 -7.172 -7.172 -6.678 -6.678 -6.613 -6.613 -4.475 -4.475 -4.469 -4.469 -4.384 -4.384 3.816 3.816 5.946 5.946 6.115 6.115 6.633 6.633 7.653 7.653 7.689 7.689 8.070 8.070 8.122 8.122 8.498 8.498 8.558 8.558 11.607 11.607 12.668 12.668 12.735 12.735 13.827 13.827 14.287 14.287 15.013 15.013 17.186 17.186 18.068 18.068
Basically look for the lines with 3 fields only and from there start to remove the line break character until the next line with 3 fields. Also I want to remove all the spaces at the beginning of the line with the 3 fields. Hope this is clearer from the above example.
I have tried the following code:
BEGIN {
ORS=" ";
}
NF==3 {x=NR+6} (NR<=x) {print}
Trouble is that I get a completely different result. I don't know how to add a \n character before the next pattern match. So I get:
0.033333 0.000000 0.000000 -46.956 -46.956 -23.678 -23.677 -23.055 -23.054 -22.974 -22.974 -8.033 -8.032 -7.375 -7.356 -7.182 -7.159 -6.695 -6.661 -6.628 -6.598 -4.477 -4.477 -4.470 -4.462 -4.387 -4.380 3.799 3.800 5.939 5.960 6.116 6.117 6.625 6.642 7.648 7.651 7.686 7.687 8.077 8.078 8.123 8.126 8.478 8.497 8.550 8.552 11.625 11.626 12.652 12.653 12.722 12.726 13.860 13.864 14.291 14.293 14.966 15.046 17.063 17.252 18.011 18.015 0.016667 0.000000 0.000000 -46.956 -46.956 -23.677 -23.677 -23.055 -23.054 -22.974 -22.974 -8.037 -8.036 -7.371 -7.361 -7.177 -7.165 -6.686 -6.669 -6.620 -6.605 -4.476 -4.475 -4.471 -4.465 -4.385 -4.382 3.811 3.812 5.942 5.952 6.115 6.115 6.629 6.638 7.651 7.653 7.688 7.689 8.072 8.073 8.122 8.123 8.491 8.501 8.556 8.556 11.612 11.612 12.665 12.665 12.730 12.733 13.835 13.837 14.288 14.289 14.991 15.031 17.132 17.225 18.053 18.055 0.000000 0.000000 0.000000 -46.956 -46.956 -23.677 -23.677 -23.055 -23.055 -22.974 -22.974 -8.038 -8.038 -7.366 -7.366 -7.172 -7.172 -6.678 -6.678 -6.613 -6.613 -4.475 -4.475 -4.469 -4.469 -4.384 -4.384 3.816 3.816 5.946 5.946 6.115 6.115 6.633 6.633 7.653 7.653 7.689 7.689 8.070 8.070 8.122 8.122 8.498 8.498 8.558 8.558 11.607 11.607 12.668 12.668 12.735 12.735 13.827 13.827 14.287 14.287 15.013 15.013 17.186 17.186 18.068
I also don't know how to get rid of all the space characters on the line with the pattern match.
One awk idea:
awk '
NF==3 { sub(/^[[:space:]]+/,"") # remove leading white space
printf "%s%s",eol,$0 # initially eol="" (undefined)
eol="\n" # next time print this line with a leading "\n" (to close out previous line)
next}
{ printf "%s%s",OFS,$0 } # OP will need to decide if the extra OFS is needed here or can be removed
END { print "" } # terminate last line of output with a "\n"
' file
This generates:
0.033333 0.000000 0.000000 -46.956 -46.956 -23.678 -23.677 -23.055 -23.054 -22.974 -22.974 -8.033 -8.032 -7.375 -7.356 -7.182 -7.159 -6.695 -6.661 -6.628 -6.598 -4.477 -4.477 -4.470 -4.462 -4.387 -4.380 3.799 3.800 5.939 5.960 6.116 6.117 6.625 6.642 7.648 7.651 7.686 7.687 8.077 8.078 8.123 8.126 8.478 8.497 8.550 8.552 11.625 11.626 12.652 12.653 12.722 12.726 13.860 13.864 14.291 14.293 14.966 15.046 17.063 17.252 18.011 18.015
0.016667 0.000000 0.000000 -46.956 -46.956 -23.677 -23.677 -23.055 -23.054 -22.974 -22.974 -8.037 -8.036 -7.371 -7.361 -7.177 -7.165 -6.686 -6.669 -6.620 -6.605 -4.476 -4.475 -4.471 -4.465 -4.385 -4.382 3.811 3.812 5.942 5.952 6.115 6.115 6.629 6.638 7.651 7.653 7.688 7.689 8.072 8.073 8.122 8.123 8.491 8.501 8.556 8.556 11.612 11.612 12.665 12.665 12.730 12.733 13.835 13.837 14.288 14.289 14.991 15.031 17.132 17.225 18.053 18.055
0.000000 0.000000 0.000000 -46.956 -46.956 -23.677 -23.677 -23.055 -23.055 -22.974 -22.974 -8.038 -8.038 -7.366 -7.366 -7.172 -7.172 -6.678 -6.678 -6.613 -6.613 -4.475 -4.475 -4.469 -4.469 -4.384 -4.384 3.816 3.816 5.946 5.946 6.115 6.115 6.633 6.633 7.653 7.653 7.689 7.689 8.070 8.070 8.122 8.122 8.498 8.498 8.558 8.558 11.607 11.607 12.668 12.668 12.735 12.735 13.827 13.827 14.287 14.287 15.013 15.013 17.186 17.186 18.068 18.068
Since you always have 7 lines per record, all you need is this, using GNU awk for multi-char RS and RT:
$ awk -v RS='([^\n]+\n){7}' -v ORS= '{$0=RT; $1=$1} 1' file
0.033333 0.000000 0.000000 -46.956 -46.956 -23.678 -23.677 -23.055 -23.054 -22.974 -22.974 -8.033 -8.032 -7.375 -7.356 -7.182 -7.159 -6.695 -6.661 -6.628 -6.598 -4.477 -4.477 -4.470 -4.462 -4.387 -4.380 3.799 3.800 5.939 5.960 6.116 6.117 6.625 6.642 7.648 7.651 7.686 7.687 8.077 8.078 8.123 8.126 8.478 8.497 8.550 8.552 11.625 11.626 12.652 12.653 12.722 12.726 13.860 13.864 14.291 14.293 14.966 15.046 17.063 17.252 18.011 18.015
0.016667 0.000000 0.000000 -46.956 -46.956 -23.677 -23.677 -23.055 -23.054 -22.974 -22.974 -8.037 -8.036 -7.371 -7.361 -7.177 -7.165 -6.686 -6.669 -6.620 -6.605 -4.476 -4.475 -4.471 -4.465 -4.385 -4.382 3.811 3.812 5.942 5.952 6.115 6.115 6.629 6.638 7.651 7.653 7.688 7.689 8.072 8.073 8.122 8.123 8.491 8.501 8.556 8.556 11.612 11.612 12.665 12.665 12.730 12.733 13.835 13.837 14.288 14.289 14.991 15.031 17.132 17.225 18.053 18.055
0.000000 0.000000 0.000000 -46.956 -46.956 -23.677 -23.677 -23.055 -23.055 -22.974 -22.974 -8.038 -8.038 -7.366 -7.366 -7.172 -7.172 -6.678 -6.678 -6.613 -6.613 -4.475 -4.475 -4.469 -4.469 -4.384 -4.384 3.816 3.816 5.946 5.946 6.115 6.115 6.633 6.633 7.653 7.653 7.689 7.689 8.070 8.070 8.122 8.122 8.498 8.498 8.558 8.558 11.607 11.607 12.668 12.668 12.735 12.735 13.827 13.827 14.287 14.287 15.013 15.013 17.186 17.186 18.068 18.06
or this using any awk:
$ awk '{rec=rec FS $0} !(NR%7){$0=rec; rec=""; $1=$1; print}' file
0.033333 0.000000 0.000000 -46.956 -46.956 -23.678 -23.677 -23.055 -23.054 -22.974 -22.974 -8.033 -8.032 -7.375 -7.356 -7.182 -7.159 -6.695 -6.661 -6.628 -6.598 -4.477 -4.477 -4.470 -4.462 -4.387 -4.380 3.799 3.800 5.939 5.960 6.116 6.117 6.625 6.642 7.648 7.651 7.686 7.687 8.077 8.078 8.123 8.126 8.478 8.497 8.550 8.552 11.625 11.626 12.652 12.653 12.722 12.726 13.860 13.864 14.291 14.293 14.966 15.046 17.063 17.252 18.011 18.015
0.016667 0.000000 0.000000 -46.956 -46.956 -23.677 -23.677 -23.055 -23.054 -22.974 -22.974 -8.037 -8.036 -7.371 -7.361 -7.177 -7.165 -6.686 -6.669 -6.620 -6.605 -4.476 -4.475 -4.471 -4.465 -4.385 -4.382 3.811 3.812 5.942 5.952 6.115 6.115 6.629 6.638 7.651 7.653 7.688 7.689 8.072 8.073 8.122 8.123 8.491 8.501 8.556 8.556 11.612 11.612 12.665 12.665 12.730 12.733 13.835 13.837 14.288 14.289 14.991 15.031 17.132 17.225 18.053 18.055
0.000000 0.000000 0.000000 -46.956 -46.956 -23.677 -23.677 -23.055 -23.055 -22.974 -22.974 -8.038 -8.038 -7.366 -7.366 -7.172 -7.172 -6.678 -6.678 -6.613 -6.613 -4.475 -4.475 -4.469 -4.469 -4.384 -4.384 3.816 3.816 5.946 5.946 6.115 6.115 6.633 6.633 7.653 7.653 7.689 7.689 8.070 8.070 8.122 8.122 8.498 8.498 8.558 8.558 11.607 11.607 12.668 12.668 12.735 12.735 13.827 13.827 14.287 14.287 15.013 15.013 17.186 17.186 18.068 18.06
awk -v ORS= '
NF==3 {
if (NR>1) print "\n"
sub(/^[[:space:]]*/,"")
}
1;
END { print "\n" }
' file
unset default newline for print (OFS=)
when 3-field line detected
print a newline (unless this is first line)
strip leading whitespace
default print (1;) - with no trailing newline
print final newline at the end
This code assumes all lines have leading whitespace (as shown in the sample input), so that no field separator is needed on joined lines.
Your original code is actually not far from working:
awk '
BEGIN { ORS=" " } # or maybe ORS=""
NF==3 {
sub(/^[[:space:]]*/,"") # strip leading whitespace
x = NR+6
}
NR<=x { print }
NR==x { printf "\n" }
' file
An even simpler solution if we know that the 3-field lines always have much more leading whitespace than any other line (e.g. 8 or more):
awk -v RS='[[:space:]]{8,}' 'gsub(/\n/,"")' file
set input record separator to be lots of spaces
strip all embedded newlines
implicit print will append a trailing newline
Note that the first (empty) record is conveniently elided because gsub fails (no newlines removed) and so does not trigger the implicit print.
Another note: This requires a version of awk that supports multi-character RS (e.g. gawk, busybox; but not mawk, original-awk).
Final note: This method, while shorter code, appears to run significantly more slowly (about 10% of the speed of the first version).
For super-slow (about 1% the speed of the first awk version), and if squeezing whitespace is not a problem, there is also the extremely compact:
<file xargs -n63

Delete node from clob if namespace exists in oracle 12c

I have a xml like below:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns4:EligibilityRequest xmlns:ns5="http://newmmis.eohhs.ma.gov/serviceobjects/versions/1.0/eligresponse" xmlns:ns1="http://newmmis.eohhs.ma.gov/serviceobjects/versions/1.0/mmiscommon" xmlns:ns4="http://newmmis.eohhs.ma.gov/serviceobjects/versions/1.0/eligrequest" xmlns:ns3="http://xmlns.eohhs.ma.gov/newMMIS/ws/2006/05/MemberInfo">
<ns4:transactionsource id_medicaid="100027128782" id_other="00001740934" id_source="HIX"/>
<ns4:demographic dte_birth="1986-10-24" cde_sex="F" num_primary_ssn="031725754" cde_citizen="C" cde_race="UNKNOW" cde_ethnicity="UNKNOW" cde_homeless="N" cde_primary_lang="ENG" cde_lang_written="ENG" num_phone_day="4135376954" email="slpaullrn#gmail.com" nam_last="Paull" nam_first="Stephanie" nam_mid_init="L" res_adr_street_1="173 Abbott street" res_adr_city="Springfield" res_adr_state="MA" res_adr_zip_code="01118" mail_adr_street_1="173 Abbott street" mail_adr_city="Springfield" mail_adr_state="MA" mail_adr_zip_code="01118" amt_indv_prem="0" amt_indv_income="0.00" amt_income_fpl="3293.34" pct_income_fpl="166.19" ind_pregnancy=" " cde_tpl_status="S" cde_born_to_st_empl=" "/>
<ns4:case num_case="00938195C" cde_case_status="1" hoh_nam_first="Stephanie" hoh_nam_last="Paull" hoh_nam_init="L" amt_family_prem="0" amt_family_mh_prem="12.00" amt_family_prem_assist="0"/>
<ns4:eligibility dte_begin_elig="2015-10-12" dte_end_elig="2016-09-06" cde_line="00" cde_elig_status="4" cde_cat="40" amt_gross_income="2470" family_size="4" dte_appl="2015-10-22" cde_region="58" cde_office="555" cde_close_reason="M1"/>
<ns4:eligibility dte_begin_elig="2016-08-13" cde_line="00" cde_elig_status="1" cde_cat="AP" amt_gross_income="3293.34" family_size="4" dte_appl="2015-10-22" cde_region="58" cde_office="555" cde_open_reason="01"/>
<ns4:uncompdeductible amt_uncmp_deductible="993" dte_effective="2016-08-13"/>
</ns4:EligibilityRequest>;
There is 2 tag of <ns4:eligibility. I want to delete one tag where we have cde_close_reason exists. Please advise
Does this work..
SQL> with MY_TABLE as
2 (
3 select XMLTYPE(
4 '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
5 <ns4:EligibilityRequest xmlns:ns5="http://newmmis.eohhs.ma.gov/serviceobjects/versions/1.0/eligresponse" xmlns:ns1="http://newmmis.eohhs.ma.gov/serviceobjects/versions/1.0/mmiscommon" xmlns:ns4="http://newmmis.eohhs.ma.gov/serviceobjects/versions/1.0/eligrequest" xmlns:ns3="http://xmlns.eohhs.ma.gov/newMMIS/ws/2006/05/MemberInfo">
6 <ns4:transactionsource id_medicaid="100027128782" id_other="00001740934" id_source="HIX"/>
7 <ns4:demographic dte_birth="1986-10-24" cde_sex="F" num_primary_ssn="031725754" cde_citizen="C" cde_race="UNKNOW" cde_ethnicity="UNKNOW" cde_homeless="N" cde_primary_lang="ENG" cde_lang_written="ENG" num_phone_day="4135376954" email="slpaullrn#gmail.com" nam_last="Paull" nam_first="Stephanie" nam_mid_init="L" res_adr_street_1="173 Abbott street" res_adr_city="Springfield" res_adr_state="MA" res_adr_zip_code="01118" mail_adr_street_1="173 Abbott street" mail_adr_city="Springfield" mail_adr_state="MA" mail_adr_zip_code="01118" amt_indv_prem="0" amt_indv_income="0.00" amt_income_fpl="3293.34" pct_income_fpl="166.19" ind_pregnancy=" " cde_tpl_status="S" cde_born_to_st_empl=" "/>
8 <ns4:case num_case="00938195C" cde_case_status="1" hoh_nam_first="Stephanie" hoh_nam_last="Paull" hoh_nam_init="L" amt_family_prem="0" amt_family_mh_prem="12.00" amt_family_prem_assist="0"/>
9 <ns4:eligibility dte_begin_elig="2015-10-12" dte_end_elig="2016-09-06" cde_line="00" cde_elig_status="4" cde_cat="40" amt_gross_income="2470" family_size="4" dte_appl="2015-10-22" cde_region="58" cde_office="555" cde_close_reason="M1"/>
10 <ns4:eligibility dte_begin_elig="2016-08-13" cde_line="00" cde_elig_status="1" cde_cat="AP" amt_gross_income="3293.34" family_size="4" dte_appl="2015-10-22" cde_region="58" cde_office="555" cde_open_reason="01"/>
11 <ns4:uncompdeductible amt_uncmp_deductible="993" dte_effective="2016-08-13"/>
12 </ns4:EligibilityRequest>') as XMLDOC
13 from dual
14 )
15 select XMLQUERY(
16 'declare namespace ns = "http://newmmis.eohhs.ma.gov/serviceobjects/versions/1.0/eligrequest"; (: :)
17 copy $NEWXML := $XML
18 modify(
19 delete nodes $NEWXML/ns:EligibilityRequest/ns:eligibility[#cde_close_reason]
20 )
21 return $NEWXML'
22 passing XMLDOC as "XML"
23 returning content
24 ) RESULT
25 from MY_TABLE
26 /
RESULT
-----------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="WINDOWS-1252" standalone='yes'?>
<ns4:EligibilityRequest xmlns:ns5="http://newmmis.eohhs.ma.gov/serviceobjects/versions/1.0/eligresponse" xmlns:ns1="http://newmmis.eohhs.ma.gov/serviceobjects/versions/1.0/mmiscommon" xmlns:ns4="http://newmmis.eohhs.ma.gov/serviceobjects/versions/1.0/eligrequest" xmlns:ns3="http://xmlns.eohhs.ma.gov/newMMIS/ws/2006/05/MemberInfo">
<ns4:transactionsource id_medicaid="100027128782" id_other="00001740934" id_source="HIX"/>
<ns4:demographic dte_birth="1986-10-24" cde_sex="F" num_primary_ssn="031725754" cde_citizen="C" cde_race="UNKNOW" cde_ethnicity="UNKNOW" cde_homeless="N" cde_primary_lang="ENG" cde_lang_written="ENG" num_phone_day="4135376954" email="slpaullrn#gmail.com" nam_last="Paull" nam_first="Stephanie" nam_mid_init="L" res_adr_street_1="173 Abbott street" res_adr_city="Springfield" res_adr_state="MA" res_adr_zip_code="01118" mail_adr_street_1="173 Abbott street" mail_adr_city="Springfield" mail_adr_state="MA" mail_adr_zip_code="01118" amt_indv_prem="0" amt_indv_income="0.00" amt_income_fpl="3293.34" pct_income_fpl="166.19" ind_pregnancy=" " cde_tpl_status="S" cde_born_to_st_empl=" "/>
<ns4:case num_case="00938195C" cde_case_status="1" hoh_nam_first="Stephanie" hoh_nam_last="Paull" hoh_nam_init="L" amt_family_prem="0" amt_family_mh_prem="12.00" amt_family_prem_assist="0"/>
<ns4:eligibility dte_begin_elig="2016-08-13" cde_line="00" cde_elig_status="1" cde_cat="AP" amt_gross_income="3293.34" family_size="4" dte_appl="2015-10-22" cde_region="58" cde_office="555" cde_open_reason="01"/>
<ns4:uncompdeductible amt_uncmp_deductible="993" dte_effective="2016-08-13"/>
</ns4:EligibilityRequest>
SQL>

XML select and update

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns4:EligibilityRequest xmlns:ns1="http://newmmis.eohhs.ma.gov/serviceobjects/versions/1.0/mmiscommon" xmlns:ns4="http://newmmis.eohhs.ma.gov/serviceobjects/versions/1.0/eligrequest" xmlns:ns3="http://xmlns.eohhs.ma.gov/newMMIS/ws/2006/05/MemberInfo" xmlns:ns5="http://newmmis.eohhs.ma.gov/serviceobjects/versions/1.0/eligresponse">
<ns4:transactionsource id_source="HIX" id_other="00000004353" id_medicaid="100208425271"/>
<ns4:demographic cde_born_to_st_empl=" " cde_born_to_ma=" " ind_pregnancy=" " pct_income_fpl="125" amt_income_fpl="1556.57" amt_indv_income="1638.5" amt_indv_prem="0" mail_adr_zip_code="02532" mail_adr_state="MA" mail_adr_city="Boston" mail_adr_street_2="APT 56" mail_adr_street_1="112 Main ST" res_adr_zip_code="02532" res_adr_state="MA" res_adr_city="Boston" res_adr_street_2="APT 56" res_adr_street_1="112 Main ST" nam_first="John" nam_last="Father" email="MAMedicaid01#hcentive.com" num_phone_day="8575550056" cde_lang_written="RUSSIN" cde_primary_lang="RUSSIN" cde_disability_stat=" " cde_homeless="N" cde_ethnicity="UNKNOW" cde_race="UNKNOW" cde_citizen="C" num_primary_ssn="278938115" cde_sex="M" dte_birth="1978-09-09"/>
<ns4:case amt_family_prem_assist="0" amt_family_mh_prem="0" amt_family_prem="0" hoh_nam_last="Father" hoh_nam_first="John" cde_case_status="2" num_case="00003235C"/>
<ns4:eligibility cde_office="555" cde_region="58" dte_appl="2014-11-13" family_size="2" amt_gross_income="1556.57" cde_cat="D1" cde_elig_status="4" cde_line="00" dte_end_elig="2014-11-13" dte_begin_elig="2014-11-03"/>
<ns4:eligibility cde_open_reason="01" cde_office="555" cde_region="58" dte_appl="2014-11-13" family_size="2" amt_gross_income="1556.57" cde_cat="D1" cde_elig_status="1" cde_line="00" dte_begin_elig="2014-11-03"/>
</ns4:EligibilityRequest>
If you open this attached XML, you can see there is 2 tags of <ns4:eligibility
I have to first select this last sub string, either by regexp_substr or simple str .. means output should be:
<ns4:eligibility cde_open_reason="01" cde_office="555" cde_region="58" dte_appl="2014-11-13" family_size="2" amt_gross_income="1556.57" cde_cat="D1" cde_elig_status="1" cde_line="00" dte_begin_elig="2014-11-03"/>
Then append this string to another xml. same like this. just append in last.
Oracle Setup:
CREATE TABLE XML_IN ( id INT, xml CLOB );
INSERT INTO XML_IN VALUES ( 1, '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns4:EligibilityRequest xmlns:ns1="http://newmmis.eohhs.ma.gov/serviceobjects/versions/1.0/mmiscommon" xmlns:ns4="http://newmmis.eohhs.ma.gov/serviceobjects/versions/1.0/eligrequest" xmlns:ns3="http://xmlns.eohhs.ma.gov/newMMIS/ws/2006/05/MemberInfo" xmlns:ns5="http://newmmis.eohhs.ma.gov/serviceobjects/versions/1.0/eligresponse">
<ns4:transactionsource id_source="HIX" id_other="00000004353" id_medicaid="100208425271"/>
<ns4:demographic cde_born_to_st_empl=" " cde_born_to_ma=" " ind_pregnancy=" " pct_income_fpl="125" amt_income_fpl="1556.57" amt_indv_income="1638.5" amt_indv_prem="0" mail_adr_zip_code="02532" mail_adr_state="MA" mail_adr_city="Boston" mail_adr_street_2="APT 56" mail_adr_street_1="112 Main ST" res_adr_zip_code="02532" res_adr_state="MA" res_adr_city="Boston" res_adr_street_2="APT 56" res_adr_street_1="112 Main ST" nam_first="John" nam_last="Father" email="MAMedicaid01#hcentive.com" num_phone_day="8575550056" cde_lang_written="RUSSIN" cde_primary_lang="RUSSIN" cde_disability_stat=" " cde_homeless="N" cde_ethnicity="UNKNOW" cde_race="UNKNOW" cde_citizen="C" num_primary_ssn="278938115" cde_sex="M" dte_birth="1978-09-09"/>
<ns4:case amt_family_prem_assist="0" amt_family_mh_prem="0" amt_family_prem="0" hoh_nam_last="Father" hoh_nam_first="John" cde_case_status="2" num_case="00003235C"/>
<ns4:eligibility cde_office="555" cde_region="58" dte_appl="2014-11-13" family_size="2" amt_gross_income="1556.57" cde_cat="D1" cde_elig_status="4" cde_line="00" dte_end_elig="2014-11-13" dte_begin_elig="2014-11-03"/>
<ns4:eligibility cde_open_reason="01" cde_office="555" cde_region="58" dte_appl="2014-11-13" family_size="2" amt_gross_income="1556.57" cde_cat="D1" cde_elig_status="1" cde_line="00" dte_begin_elig="2014-11-03"/>
</ns4:EligibilityRequest>');
CREATE TABLE XML_OUT( id INT, xml CLOB );
INSERT INTO XML_OUT VALUES ( 1, '<test><attribute>existing</attribute></test>' );
Query:
MERGE INTO XML_OUT o
USING XML_IN i ON ( o.id = i.id )
WHEN MATCHED THEN
UPDATE
SET xml = APPENDCHILDXML(
XMLType( o.xml ),
'/test',
EXTRACT(
XMLType( i.xml ),
'//ns4:EligibilityRequest/ns4:eligibility[last()]',
'xmlns:ns4="http://newmmis.eohhs.ma.gov/serviceobjects/versions/1.0/eligrequest"'
)
).getClobVal();
Output:
SELECT * FROM XML_OUT;
ID XML
---------- ----------------------------------------------------------------------
1 <test><attribute>existing</attribute><ns4:eligibility xmlns:ns4="http:
//newmmis.eohhs.ma.gov/serviceobjects/versions/1.0/eligrequest" cde_ope
n_reason="01" cde_office="555" cde_region="58" dte_appl="2014-11-13" fa
mily_size="2" amt_gross_income="1556.57" cde_cat="D1" cde_elig_status="
1" cde_line="00" dte_begin_elig="2014-11-03"/></test>

How can I pass a session variable as parameter for maxRedeliveryAttempts field in rollback-exception-strategy component in Mule?

Below is the Mule configuration XML.
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8090" doc:name="HTTP Listener Configuration"/>
<flow name="testflowFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<set-session-variable variableName="count" value="#[message.inboundProperties.'http.query.params'.retrycount]" doc:name="count Session Variable"/>
<set-payload value="#[sessionVars.count]" doc:name="Set Payload"/>
<file:outbound-endpoint path="C:\Users\y0134079\Desktop" responseTimeout="10000" doc:name="File"/>
<set-payload value="#[sessionVars.count]" doc:name="Set Payload"/>
<rollback-exception-strategy maxRedeliveryAttempts="#[sessionVars.count]" doc:name="Rollback Exception Strategy"/>
</flow>
I trying to pass the maximum retries attempt in one of the query parameters (retrycount) in the HTTP request. But the maxredeliveryattempts field expect a integer and as the provided query parameter is a string the build has failed as it is not able o convert from string to integer. Any suggestions on this ?
Error :
*****Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Integer' for property 'maxRedeliveryAttempts'; nested exception is java.lang.NumberFormatException: For input string: "[sessionVars.count]"
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:468) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]*****
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:494) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:488) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1464) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1423) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1159) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:276) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1418) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1159) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:633) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) ~[spring-context-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) ~[spring-context-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.mule.config.spring.SpringRegistry.doInitialise(SpringRegistry.java:86) ~[mule-module-spring-config-3.6.1.jar:3.6.1]
at org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:105) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.config.spring.SpringXmlConfigurationBuilder.createSpringRegistry(SpringXmlConfigurationBuilder.java:135) ~[mule-module-spring-config-3.6.1.jar:3.6.1]
at org.mule.config.spring.SpringXmlConfigurationBuilder.doConfigure(SpringXmlConfigurationBuilder.java:90) ~[mule-module-spring-config-3.6.1.jar:3.6.1]
at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:43) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:69) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.config.builders.AutoConfigurationBuilder.autoConfigure(AutoConfigurationBuilder.java:101) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.config.builders.AutoConfigurationBuilder.doConfigure(AutoConfigurationBuilder.java:52) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:43) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:69) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.context.DefaultMuleContextFactory$1.configure(DefaultMuleContextFactory.java:84) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.context.DefaultMuleContextFactory.doCreateMuleContext(DefaultMuleContextFactory.java:217) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:76) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:187) ~[mule-module-launcher-3.6.1.jar:3.6.1]
... 14 more
Caused by: java.lang.NumberFormatException: For input string: "[sessionVars.count]"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[?:1.7.0_79]
at java.lang.Integer.parseInt(Integer.java:492) ~[?:1.7.0_79]
at java.lang.Integer.valueOf(Integer.java:556) ~[?:1.7.0_79]
at java.lang.Integer.decode(Integer.java:984) ~[?:1.7.0_79]
at org.springframework.util.NumberUtils.parseNumber(NumberUtils.java:155) ~[spring-core-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.propertyeditors.CustomNumberEditor.setAsText(CustomNumberEditor.java:115) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.TypeConverterDelegate.doConvertTextValue(TypeConverterDelegate.java:455) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeConverterDelegate.java:427) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:181) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:448) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:494) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:488) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1464) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1423) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1159) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:276) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1418) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1159) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:633) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) ~[spring-context-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) ~[spring-context-3.2.10.RELEASE.jar:3.2.10.RELEASE]
at org.mule.config.spring.SpringRegistry.doInitialise(SpringRegistry.java:86) ~[mule-module-spring-config-3.6.1.jar:3.6.1]
at org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:105) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.config.spring.SpringXmlConfigurationBuilder.createSpringRegistry(SpringXmlConfigurationBuilder.java:135) ~[mule-module-spring-config-3.6.1.jar:3.6.1]
at org.mule.config.spring.SpringXmlConfigurationBuilder.doConfigure(SpringXmlConfigurationBuilder.java:90) ~[mule-module-spring-config-3.6.1.jar:3.6.1]
at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:43) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:69) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.config.builders.AutoConfigurationBuilder.autoConfigure(AutoConfigurationBuilder.java:101) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.config.builders.AutoConfigurationBuilder.doConfigure(AutoConfigurationBuilder.java:52) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:43) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:69) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.context.DefaultMuleContextFactory$1.configure(DefaultMuleContextFactory.java:84) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.context.DefaultMuleContextFactory.doCreateMuleContext(DefaultMuleContextFactory.java:217) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:76) ~[mule-core-3.6.1.jar:3.6.1]
at org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:187) ~[mule-module-launcher-3.6.1.jar:3.6.1]
... 14 more
INFO 2016-05-03 08:13:33,029 [main] org.mule.module.launcher.DeploymentDirectoryWatcher:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Mule is up and kicking (every 5000ms) +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO 2016-05-03 08:13:33,239 [main] org.mule.module.launcher.StartupSummaryDeploymentListener:
DOMAIN + - - * - - + STATUS + - - *
default * DEPLOYED *
APPLICATION + - - * - - + DOMAIN + - - * - - + STATUS + - - *
testflow * default * FAILED *
That attribute does not support MEL expressions. It supports spring property placeholders, but not dynamic MEL expressions. It is evaluated when initialized not runtime.
Use #[Integer.parseInt(sessionVars.count)]

OPENXML to extract data from XML and add to the table

I have a XML file from where I want to get the data and place it into the SQL table. My problem is the path is different in the same XML file.
For an example,
one path = 'root/DescriptorRecord/DescriptorName'
second path = 'root/DescriptorRecord/ConceptList/Concept/TermList/Term'
I have no clue that how to get a value from two different path in a same XML.
Following is my XML :
<root>
<DescriptorRecord DescriptorClass = "1">
<DescriptorName>
<String>abc</String>
</DescriptorName>
<ConceptList>
<Concept PreferredConceptYN="Y">
<TermList>
<Term ConceptPreferredTermYN="Y" IsPermutedTermYN="N" LexicalTag="NON" PrintFlagYN="Y" RecordPreferredTermYN="Y">
<String>abc</String>
</Term>
<Term ConceptPreferredTermYN="N" IsPermutedTermYN="N" LexicalTag="NON" PrintFlagYN="N" RecordPreferredTermYN="N">
<String>pqr</String>
</Term>
<Term ConceptPreferredTermYN="N" IsPermutedTermYN="N" LexicalTag="NON" PrintFlagYN="Y" RecordPreferredTermYN="N">
<String>xyz</String>
</Term>
</TermList>
</Concept>
</ConceptList>
</DescriptorRecord>
<DescriptorRecord DescriptorClass = "1">
<DescriptorName>
<String>Numerics</String>
</DescriptorName>
<ConceptList>
<Concept PreferredConceptYN="Y">
<TermList>
<Term ConceptPreferredTermYN="Y" IsPermutedTermYN="N" LexicalTag="NON" PrintFlagYN="Y" RecordPreferredTermYN="Y">
<String>123</String>
</Term>
<Term ConceptPreferredTermYN="N" IsPermutedTermYN="N" LexicalTag="NON" PrintFlagYN="N" RecordPreferredTermYN="N">
<String>456</String>
</Term>
<Term ConceptPreferredTermYN="N" IsPermutedTermYN="N" LexicalTag="NON" PrintFlagYN="Y" RecordPreferredTermYN="N">
<String>789</String>
</Term>
</TermList>
</Concept>
</ConceptList>
</DescriptorRecord>
</root>
My SQL query :
DECLARE #XML AS XML, #hDoc AS INT, #SQL NVARCHAR (MAX)
SELECT #XML = XMLData FROM XMLwithOpenXML
EXEC sp_xml_preparedocument #hDoc OUTPUT, #XML
SELECT Descriptor, Terms
FROM OPENXML(#hDoc, 'root/DescriptorRecord/DescriptorName')
WITH
(
Descriptor [varchar](100) 'String',
Terms [varchar](100) 'String'
)
SELECT Terms
FROM OPENXML(#hDoc, 'root/DescriptorRecord/ConceptList/Concept/TermList/Term')
WITH
(
Descriptor [varchar](100) 'String'
Terms [varchar](100) 'String'
)
EXEC sp_xml_removedocument #hDoc
GO
Result :
Expected Result
So, setting up your sample in a variable:
DECLARE #X XML = N'<root>
<DescriptorRecord DescriptorClass = "1">
<DescriptorName>
<String>abc</String>
</DescriptorName>
<ConceptList>
<Concept PreferredConceptYN="Y">
<TermList>
<Term ConceptPreferredTermYN="Y" IsPermutedTermYN="N" LexicalTag="NON" PrintFlagYN="Y" RecordPreferredTermYN="Y">
<String>abc</String>
</Term>
<Term ConceptPreferredTermYN="N" IsPermutedTermYN="N" LexicalTag="NON" PrintFlagYN="N" RecordPreferredTermYN="N">
<String>pqr</String>
</Term>
<Term ConceptPreferredTermYN="N" IsPermutedTermYN="N" LexicalTag="NON" PrintFlagYN="Y" RecordPreferredTermYN="N">
<String>xyz</String>
</Term>
</TermList>
</Concept>
</ConceptList>
</DescriptorRecord>
<DescriptorRecord DescriptorClass = "1">
<DescriptorName>
<String>Numerics</String>
</DescriptorName>
<ConceptList>
<Concept PreferredConceptYN="Y">
<TermList>
<Term ConceptPreferredTermYN="Y" IsPermutedTermYN="N" LexicalTag="NON" PrintFlagYN="Y" RecordPreferredTermYN="Y">
<String>123</String>
</Term>
<Term ConceptPreferredTermYN="N" IsPermutedTermYN="N" LexicalTag="NON" PrintFlagYN="N" RecordPreferredTermYN="N">
<String>456</String>
</Term>
<Term ConceptPreferredTermYN="N" IsPermutedTermYN="N" LexicalTag="NON" PrintFlagYN="Y" RecordPreferredTermYN="N">
<String>789</String>
</Term>
</TermList>
</Concept>
</ConceptList>
</DescriptorRecord>
</root>'
You'll want to select the descriptors first in an inner query, and return the results to an outer query, where you can use the descriptor column as a xpath criteria in the second .nodes() call. Like so:
SELECT Descriptor.Data.value('./DescriptorName[1]/String[1]','nvarchar(200)') AS Descriptor, Terms.Data.value('.','nvarchar(200)') AS Terms
FROM #x.nodes('root/DescriptorRecord') Descriptor(Data)
cross apply Descriptor.Data.nodes('./ConceptList/Concept/TermList/Term/String') Terms(Data)
EDIT: An attempt to make it less computationally expensive.