Please assist me to extract data from XML, I am scarmbling to find a logic with little knowledge in Powershell script. I need this logic to be implemented without installing additional modules/libraries in powershell.
I need to get the maximum priority in the XML grouped by KEY along with HITS (H) count.
Script shared below by @roadrunner works as expected which is great!, but when I run for larger XML file (2GB xml file), it takes long time to process, is there something we can do to mutli-thread and reduce the processing time ?
<ABC-FOF-PROCESS>
<H>
<PRIORITY>-14</PRIORITY>
<KEY>F637A146-3437AB82-BA659D4A-17AC7FBF</KEY>
</H>
<H>
<PRIORITY>-14</PRIORITY>
<KEY>F637A146-3437AB82-BA659D4A-17AC7FBF</KEY>
</H>
<H>
<PRIORITY>-3</PRIORITY>
<KEY>D6306210-CF424F11-8E2D3496-E6CE1CA7</KEY>
</H>
<H>
<PRIORITY>1</PRIORITY>
<KEY>D6306210-CF424F11-8E2D3496-E6CE1CA7</KEY>
</H>
<H>
<PRIORITY>-3</PRIORITY>
<KEY>4EFR02B4-ADFDAF12-3C123II2-ADAFADFD</KEY>
</H>
<H>
<PRIORITY>-14</PRIORITY>
<KEY>5D2702B2-ECE8F1FB-3CEC3229-5FE4C4BC</KEY>
</H>
</ABC-FOF-PROCESS>
For Example logic of expected output should be something like this:
1nd and 2nd Hit tag has Priority -14 and grouped into one common KEY, and the max prioirty is -14.
Output Slab for first 2 hits:
PRIOIRTY KEY HITS
-14 1 2
3rd and 4th Hit tag has maximum Priority 1 with one common KEY. Output Slab:
PRIOIRTY KEY HITS
1 1 2
5th H tag has one Priority -3 with one common KEY. Output Slab:
PRIOIRTY KEY HITS
-3 1 1
6th H tag has one Priority -3 with one common KEY. Output Slab:
PRIOIRTY KEY HITS
-14 1 1
FINAL OUTPUT (Aggregated):
PRIOIRTY KEY HITS
1 1 2
-3 1 1
-14 2 3
Test Case:
<ABC-FOF-PROCESS>
<H>
<PRIORITY>0</PRIORITY>
<KEY>F637A146-3437AB82-BA659D4A-17AC7FBF</KEY>
</H>
<H>
<PRIORITY>-2</PRIORITY>
<KEY>F637A146-3437AB82-BA659D4A-17AC7FBF</KEY>
</H>
<H>
<PRIORITY>-2</PRIORITY>
<KEY>F637A146-3437AB82-BA659D4A-17AC7FBF</KEY>
</H>
<H>
<PRIORITY>6</PRIORITY>
<KEY>F637A146-3437AB82-BA659D4A-17AC7FBF</KEY>
</H>
<H>
<PRIORITY>3</PRIORITY>
<KEY>F637A146-3437AB82-BA659D4A-17AC7FBF</KEY>
</H>
<H>
<PRIORITY>-3</PRIORITY>
<KEY>F637A146-3437AB82-BA659D4A-17AC7FBF</KEY>
</H>
<H>
<PRIORITY>3</PRIORITY>
<KEY>F637A146-3437AB82-BA659D4A-17AC7FBF</KEY>
</H>
</ABC-FOF-PROCESS>
Actual Output:
PRIORITY KEY HITS
-------- --- ----
6 1 1
3 1 2
0 1 1
-2 1 2
-3 1 1
Expected Output: Only the maximum priority should be picked up summing up all the hits for a common key (F637A146-3437AB82-BA659D4A-17AC7FBF)
PRIORITY KEY HITS
-------- --- ----
6 1 7
In my OP 3rd and 4th Hit tag has maximum Priority 1 (-3 > 1) with one common KEY (D6306210-CF424F11-8E2D3496-E6CE1CA7).