I am working with an XML document and I am not sure how to parse it to find a particular node.
In the example below I'd be searching for the ProductB and expecting to identify the Bee Hive
<PRODUCTS>
<PRODUCT_LEVEL_1>
<PRODUCT_ID>ProductA</PRODUCT_ID>
<PRODUCT_NAME>Ant Hill</PRODUCT_NAME>
<PRODUCT_ID>ProductB</PRODUCT_ID>
<PRODUCT_NAME>Bee Hive</PRODUCT_NAME>
<PRODUCT_ID>ProductC</PRODUCT_ID>
<PRODUCT_NAME>Centipede Hotel</PRODUCT_NAME>
</PRODUCT_LEVEL_1>
</PRODUCTS>
I'm not even sure how to refer to this format of XML which is making it difficult to search for.
Any assistance gratefully received.
Edit: At present I am loading the XML from a file using the following:
System.Xml.XmlDocument] $xd = new-object System.Xml.XmlDocument
$file = resolve-path($inputFile)
$xd.load($file)
$nodelist = $xd.selectnodes("/PRODUCTS/PRODUCT_LEVEL_1")
foreach ($documentNode in $nodelist) {
#do some stuff
}
The actual XML file has loads of other junk in too but I stripped it out in the hopes of focusing on the bits I need. Perhaps I have stripped too much and the context has been lost?
SelectNodes()argument with the-Xpathvalue @PetSerAl suggested