I am trying to delete files in a folder based on any folder containing an XML file with the tag Modality containing anyType="CT" but quickly an into an issue trying to filter by XML content
I am able to return some content, but as soon as I try any filtering or to try and drill down into the content I get an empty result.
This is as deep as I can query and still return content from the xml file
$xmlfile = get-Content .\7.86.7.7053.61.159438.472144765.1719.XML
$xmlfile.ArrayOfPublicXMLElement.PublicXMLElement.ElementName
as soon as I try to drill deeper down I get no result e.g.
$xmlfile.ArrayOfPublicXMLElement.PublicXMLElement.Elementname |where {$_.name -eq "Modality"}
$xmlfile.ArrayOfPublicXMLElement.PublicXMLElement.Elementname |where {$_.name -eq "anyType"}
$xmlfile.ArrayOfPublicXMLElement.PublicXMLElement.Elementname |where {$_.name -eq "CT"}
$xmlfile.ArrayOfPublicXMLElement.PublicXMLElement | where {$_.name -eq "00080060"}
Here is a copy of the XML I am trying to filter I am assuming it is due to the format of the XML file I am having so much difficulty or just a massive misunderstanding of XML format or how powershell interacts with it?
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfPublicXMLElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<PublicXMLElement>
<ElementName>Acquisition Time</ElementName>
<Tag>00080032</Tag>
<VR>TM</VR>
<ElementData>
<anyType xsi:type="xsd:string">105343</anyType>
</ElementData>
</PublicXMLElement> <ElementName>Accession Number</ElementName>
<Tag>00080050</Tag>
<VR>SH</VR>
<ElementData>
<anyType xsi:type="xsd:string" />
</ElementData>
</PublicXMLElement>
<PublicXMLElement>
<ElementName>Modality</ElementName>
<Tag>00080060</Tag>
<VR>CS</VR>
<ElementData>
<anyType xsi:type="xsd:string">CT</anyType>
</ElementData>
</PublicXMLElement>
<PublicXMLElement>
<ElementName>Station Name</ElementName>
<Tag>00081010</Tag>
<VR>SH</VR>
<ElementData>
<anyType xsi:type="xsd:string">M_Source</anyType>
</ElementData>
</PublicXMLElement>
<PublicXMLElement>
<ElementName>Rescale Slope</ElementName>
<Tag>00281053</Tag>
<VR>DS</VR>
<ElementData>
<anyType xsi:type="xsd:string">1.0</anyType>
</ElementData>
</PublicXMLElement>
</ArrayOfPublicXMLElement>
</PublicXMLElement>has no matching start tag.