Thursday 17 June 2010

Get-XMLNode.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script re-implements an MSDN Sample in PowerShell 
  4. .DESCRIPTION 
  5.     This script creates and manipulates an XML Document 
  6. .NOTES 
  7.     File Name  : Get-XMLNode.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell Version 2.0 
  10. .LINK 
  11.     This script posted to: 
  12.         http://www.pshscripts.blogspot.com 
  13.     MSDN Sample posted at: 
  14.         http://msdn.microsoft.com/en-us/library/system.xml.xmlelement.name.aspx 
  15. .EXAMPLE 
  16.     [ps] c:\foo> .\Get-XMLElement.ps1 
  17.     bk:ISBN = 1-861001-57-5 
  18.        namespaceURI=urn:samples 
  19. #> 
  20.  
  21. # Create new document 
  22. $doc = New-Object System.Xml.XmlDocument 
  23.   
  24. # Load XML document from text 
  25. $doc.LoadXml("<book xmlns:bk='urn:samples'>"
  26.                 "<bk:ISBN>1-861001-57-5</bk:ISBN>"
  27.                 "<title>Pride And Prejudice</title>"
  28.                 "</book>"
  29.  
  30. # Display information on the ISBN element. 
  31. $elem = $doc.DocumentElement.FirstChild; 
  32. "{0} = {1}" -f $elem.Name, $elem.InnerText 
  33. "`tnamespaceURI=" + $elem.NamespaceURI 
  34. # End of Script

No comments: