Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Reads xml file of persons with name, age and siblings
- # Outputs each person + siblings as text
- # Tested with PS v5.1
- # November 2018, Countryen
- # ==================
- # Configuration
- $CFG = @{
- CRLF = [Environment]::NewLine
- InputPath = ".\data.xml"
- OutputPath = ".\data.txt"
- }
- # Read content of file, convert to XML
- $xml = [Xml](Get-Content $CFG.InputPath)
- # Find all elements (sequence)
- $elements = $xml.Root.Person
- # Filter (many elements
- $result = $elements | % { $_.Name, "----", ($_.Siblings.Sibling | % { "> " + $_.Name }), $CFG.CRLF }
- # Output result to file
- $result | Out-File $CFG.OutputPath
- ### Example Output:
- # Mike
- # -----
- # > June
- # > July
- #
- # Christian
- # >
- #
- ### Example XML:
- # <Root>
- # <Person>
- # <Name>Mike</Name>
- # <Age>22</Age>
- # <Siblings>
- # <Sibling>
- # <Name>June</Name>
- # </Sibling>
- # <Sibling>
- # <Name>July</Name>
- # </Sibling>
- # </Siblings>
- # </Person>
- # <Person>
- # <Name>Christian</Name>
- # <Age>16</Age>
- # </Person>
- # </Root>
Add Comment
Please, Sign In to add comment