Hello,
I have a power shell script that reads an XML file and I am having issues getting just the value of one of the nodes.
Below is a snippet of the XML file.
<?xml version="1.0" encoding="utf-8"?>
<file_type>
<FName>
<name>511</name>
<DXF>True</DXF>
<STL>True</STL>
<STP>False</STP>
</FName>
<FName>
<name>600</name>
<DXF>False</DXF>
<STL>True</STL>
<STP>True</STP>
</FName>
<FName>
<name>700</name>
<DXF>True</DXF>
<STL>False</STL>
<STP>False</STP>
</FName>
</file_type>
Below is the script that reads the XML file.
$XMLPath = "C:\temp\AmerluxExportFilter.xml"
[XML]$xml = Get-Content $XMLPath
#This variable is set for testing purposes
$fileNameFirstXChar="511"
#Search XML file for match. If found set export choices for DXF, STP, and STL files.
If ($Xml.file_type.FName | Where-Object { $_.Name -eq $fileNameFirstXChar }) {
write-host "Found match in XML file... '$($fileNameFirstXChar)'..."
$DXFChoice= $Xml.file_type.FName | Where-Object {$_.Name -eq $fileNameFirstXChar } | Select-Object -Property DXF
$STPChoice= $Xml.file_type.FName | Where-Object {$_.Name -eq $fileNameFirstXChar } | Select-Object -Property STP
$STLChoice= $Xml.file_type.FName | Where-Object {$_.Name -eq $fileNameFirstXChar } | Select-Object -Property STL
write-host "DXFChoice... '$($DXFChoice)'..."
write-host "STPChoice... '$($STPChoice)'..."
write-host "STLChoice... '$($STLChoice)'..."
}
else {
write-host "NO Found match in XML file for... '$($fileNameFirstXChar)'..."
}
The output is shown below.
Found match in XML file… ‘511’…
DXFChoice… ‘@{DXF=True}’…
STPChoice… ‘@{STP=True}’…
STLChoice… ‘@{STL=False}’…
I am not sure what data type is being output.
I only need the value, i.e. True or False and it would be great if it could be boolean.
I’m open to suggestions or best practices.
Thank you in advance.