This CodeProject article can be useful:
PowerShell and XML[
^].
This is another short article:
https://devcentral.f5.com/blogs/us/powershell-abcs-x-is-for-xml[
^].
For some more detail, please see:
http://www.pavleck.net/powershell-cookbook/ch10.html[
^].
However, these are just the PowerShell-specific aspects of it. If you need more serious approach, you can use all power of .NET API. First, you need to know how to access .NET assemblies:
http://www.pavleck.net/powershell-cookbook/ch17.html#access_a_net_sdk_library[
^].
This is how you can load the assembly, on one example:
$null = [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
And then you can use all power of .NET parsing and writing available in .NET BCL. Here is my short overview of what you can use:
- Use
System.Xml.XmlDocument
class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^]. - Use the classes
System.Xml.XmlTextWriter
and System.Xml.XmlTextReader
; this is the fastest way of reading, especially is you need to skip some data.
See http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx[^], http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^]. - Use the class
System.Xml.Linq.XDocument
; this is the most adequate way similar to that of XmlDocument
, supporting LINQ to XML Programming.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].
You can also use C# or VB.NET code in your script using
Add-Type
:
http://www.pavleck.net/powershell-cookbook/ch17.html#define_extend_net_class[
^].
Happy New Year!
—SA