xml file balance and control

I have to validate an xml file by counting number of segments in the file between ST and SE segments and balancing it against the count provided in the SE segment field. These ST and SE segments can repeat multiple times through out the file so I have to do this validation multiple times. Please let me know what is the best way to do this. TIA.

Sam, welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

This forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request.

What have you tried so far? We expect you to make an own attempt to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further.

Have you tried anything? There are a tons of example of XML parsing is you simply searched. If the number of segments is static, for instance there should always be 5 child elements under each, you can use a XSD. If the number is dynamic and you need to confirm the count, use dot notation to get a count.