But I need ad-hoc answers, it's not about a specific thing I try to achieve, but mostly to learn
And yet every answer given here can be found on Google ... if you're going to learn anything, learn to ask the right questions.
Input
<?xml version="1.0" encoding="ISO8859-1" ?>
<html:products>
<html:prod id="prod1">
<html:referenceData>
<html:product>
<html:classificationType>PRD</html:classificationType>
<html:productType>PRD_XE</html:productType>
<html:productId>10004</html:productId>
<html:assignedDate>2018-07-23</html:assignedDate>
</html:product>
<html:book>
<html:name>REPAIRS</html:name>
<html:Entity>REP_XE</html:legalEntity>
<html:location>ED</html:location>
</html:book>
</html:referenceData>
</html:prod>
<html:prod id="prod2">
<html:referenceData>
<html:product>
<html:classificationType>PRD2</html:classificationType>
<html:productType>PRD_XE2</html:productType>
<html:productId>10005</html:productId>
<html:assignedDate>2018-12-23</html:assignedDate>
</html:product>
<html:book>
<html:name>REPAIRS2</html:name>
<html:Entity>REP_XE2</html:legalEntity>
<html:location>ED2</html:location>
</html:book>
</html:referenceData>
</html:prod>
<html:prod id="prod3">
<html:referenceData>
<html:product>
<html:classificationType>PRD3</html:classificationType>
<html:productType>PRD_XE3</html:productType>
<html:productId>10014</html:productId>
<html:assignedDate>2013-07-23</html:assignedDate>
</html:product>
<html:book>
<html:name>REPAIRS3</html:name>
<html:Entity>REP_XE3</html:legalEntity>
<html:location>ED3</html:location>
</html:book>
</html:referenceData>
</html:prod>
<html:prod id="prod4">
<html:referenceData>
<html:product>
<html:classificationType>PRD4</html:classificationType>
<html:productType>PRD_XE4</html:productType>
<html:productId>10567</html:productId>
<html:assignedDate>2010-07-23</html:assignedDate>
</html:product>
<html:book>
<html:name>REPAIRS4</html:name>
<html:Entity>REP_XE4</html:legalEntity>
<html:location>ED4</html:location>
</html:book>
</html:referenceData>
</html:prod>
<html:prod id="prod5">
<html:referenceData>
<html:product>
<html:classificationType>PRD5</html:classificationType>
<html:productType>PRD_XE5</html:productType>
<html:productId>10004890</html:productId>
<html:assignedDate>2015-05-15</html:assignedDate>
</html:product>
<html:book>
<html:name>REPAIRS5</html:name>
<html:Entity>REP_XE5</html:legalEntity>
<html:location>ED5</html:location>
</html:book>
</html:referenceData>
</html:prod>
</html:products>
gc "test.xml" -Raw | sls '(?smi)(<html:prod\s.+?/html:prod>)' -AllMatches | % {$_.Matches} | % { ((((($_.Value) -replace '(<[^>]+>|\s)', '; ') -replace '`r', '') -replace '`n', '') -replace '(;\s)(;\s)+', '$1').Trim('; ') }
Output
PRD; PRD_XE; 10004; 2018-07-23; REPAIRS; REP_XE; ED
PRD2; PRD_XE2; 10005; 2018-12-23; REPAIRS2; REP_XE2; ED2
PRD3; PRD_XE3; 10014; 2013-07-23; REPAIRS3; REP_XE3; ED3
PRD4; PRD_XE4; 10567; 2010-07-23; REPAIRS4; REP_XE4; ED4
PRD5; PRD_XE5; 10004890; 2015-05-15; REPAIRS5; REP_XE5; ED5
- Stop trying to put it all on one line, (just because I do doesn't mean you should).
- Stop using Powershell shortcuts until you to understand what they are because they make the source harder to read, (and yes, I used them for a reason).
- No, the output is not exactly what you wanted - not my problem since getting any coherent information is like extracting a 3 course meal from a lump of granite and takes just as long.
- If it doesn't work on the files you have - again, not my problem - see above reason.
Your homework to increase your knowledge: Render the above one line into a multi-line Powershell script with
no command shortcuts.
Non-optional extra: Tell us what the RegEx is doing.
Optional extra: Fix it so you get the
prod value from the input data at the start of the output lines.
Optional extra: Make it process multiple files
without using
gc *.xml anywhere in it.
If it doesn't work on your data,
you tell us why, don't ask us, we're not mind readers.
I'm done.