Parse a string in powershell to take a section of text between two XML tags.
Posted on 2014-04-30
Using powershell, how can I grab a string that sits between two XML tags and assign it to a variable?
I am parsing text in powershell. The line of text looks something like this:
I need to save the value between the XML tags as a variable.
In this case the word "commercial" should be saved into the variable.
The text lines will have leading spaces
The XML tags and the word we want to will vary in length.
The value between the XML tags may have a space in it.
Examples of the result we'd like :
String = <JobName>Commercial</JobName>
Variable = Commercial
String = <JobDescription>Residential</JobDescription>
Variable = Residential
String = <JobActive>In Progress</JobActive>
Variable = In Progress