0

novice here trying to use powershell to return the text within cdata tags within multiple files in a folder structure and then write to a csv.

The other option would be to trim either side of the cdata on output as it could appear at different positions within a line.

Thanks in advance.

The below returns the file name, line and cdata tags but with variable spacing but really just after the contents within the cdata..

Get-ChildItem -Path "C:\temp" -Filter "*.xml" -Recurse  | 
    Where-Object { !$_.PSItem } |
    Select-String  "\[[^\[\]]*?\]" -Pattern > export.csv

The xml will look something like this:

<Name>          <![CDATA[value]]>.    </Name>
<Name><![CDATA[value]]></Name>
<Name>                <![CDATA[value]]</Name>
Mdog202
  • 1
  • 1
  • Why not use Powershell's native XML features? – vonPryz Feb 13 '23 at 21:47
  • 1
    Always include sample data to increase your odds of getting a response. – albvar Feb 14 '23 at 03:34
  • To extract `cdata` from where "*xml will look something like this*", you would need to do *something like* the answer in the duplicate [How to read CDATA in XML file with PowerShell?](https://stackoverflow.com/questions/1274070/how-to-read-cdata-in-xml-file-with-powershell). If you are looking for a more specific answer, you will need to be more specific in your question with a [mcve] that works and an explanation of the actual results and expected results. See [how to ask](https://stackoverflow.com/help/how-to-ask). – iRon Feb 14 '23 at 07:01

0 Answers0