I have lots of XML files which contain data I need. I need to parse out an attribute as the column headers and the InnerXml as the values. I can handle looping through the documents, but pulling the individual attribute and innerxml is throwing me
XML file Example
<?xml version="1.0" encoding="UTF-8"?>
<files>
<file type="lcmContract" id="72187_fi20190000046444">
<title>Bacon Cheeseburger</title>
<field name="lcmHeaderGrp"></field>
<field name="lcmHasNote">_image=custom/crmNote.gif</field>
<field name="lcmSubject">Bacon Cheeseburgers are Good</field>
<field name="lcmPrincipal">Frontline Rock</field>
<field name="lcmClosingDate">@20190704</field>
<field name="lcmAclList">
Royalties
LEGAL_DEPT
LegalExt
MktgRock
AllExceptRestricted
LegalTemp
LEGAL_DEPT_READ
lcmAdmin
CONTRACT-Administrator
</field>
</file>
</files>
Table I'm trying to get to:
title | lcmSubject | lcmPrincipal | lcmClosingDate | lcmAclList |
---|---|---|---|---|
Bacon Cheeseburger | Bacon Cheeseburgers are Good | Frontline Rock | @20190704 | Royalties,LEGAL_DEPT,LegalExt,MktgRock,AllExceptRestricted,LegalTemp,LEGAL_DEPT_READ,lcmAdmin,CONTRACT-Administrator |
I can the lists of data I'm expecting, but can't Pivot them into headers and values. I also don't really NEED all the data, so if I can figure out how to limit the columns based on the Attribute Name that'd be helpful.
Some of the scripts I've used:
[xml]$xmlFile = Get-Content -Path C:\Doc.xml
$xmlFile.files.file.ChildNodes | Select-Object -Expand Name
This brings back column headers, but in a list view
$xmlFile.files.file.ChildNodes | Select-Object -Expand InnerXml
This brings back values, but in a list view