Keith's profileKeith Hill's BlogPhotosBlogListsMore ![]() | Help |
|
February 02 XLinq PowerShell Module to Wrap XLinq APIThis is pretty early stuff but I thought I would share it anyway. I really like PowerShell as a .NET REPL. It is the first way I’ll try an experiment with the various .NET APIs. That doesn’t always work out and in the early CTPs of PowerShell I was having a hard time getting XLinq to work as I expected. So I wrote this XLinq.psm1 module to make it a bit easier. This does require CTP3 of Windows PowerShell v2.0 (or Windows 7 which has this version installed). Note: you really have to resist the urge to use commas to separate arguments. :-) Here’s an example usage: Contents of file: XLinqExample.ps1 1: Import-Module XLinq 2: 3: $doc = ` 4: XDoc `5: (XDecl -encoding 'utf-16') ` 6: (XElem root ` 7: (XElem author ` 8: (XAttr fname Michael) ` 9: (XAttr lname Crichton) ` 10: (XElem books ` 11: (XElem book ` 12: (XAttr title Prey) ` 13: ) ` 14: ) ` 15: ) `16: (XElem author ` 17: (XAttr fname Jon) ` 18: (XAttr lname Skeet) ` 19: (XElem books ` 20: (XElem book ` 21: (XAttr title 'C# in Depth') ` 22: ) ` 23: ) ` 24: ) ` 25: ) 26: 27: $path = [IO.Path]::GetTempFileName() 28: $doc.Save($path) 29: Get-Content $path 30: Remove-Item $path
I’m not claiming this is the best way to manipulate XML in PowerShell, however if you want to do a quick experiment using XLinq this module comes in handy. As always, if you find any bugs please drop me a line. Update 02/13/2009: Updated the module to handle pipeline input and scriptblocks (inspired by a similar module that Josh Einstein came up with). psmdtag:module: XLinq |
|
|