Geek Noise
Rants, rambles, news and notes by Peter Provost
09

My Latest Powershell/XML Hack

Friday, 9 February 2007 14:30 by Peter Provost

I have a little text file I keep quotes and silly quips in. I've been collecting it for years. I recently installed a little program called Messenger Plus Live that lets you run scripts and do all kinds of other interesting things to Live Messenger.

Long story short, there is a script for Messenger Plus that lets you have a database of quotes that rotate in your tagline in Messenger. I wanted my little text database in there, but it had its own XML file format.

Powershell to the rescue:

$lines = gc 'quotes.txt'
$dom = [xml] (gc 'quotes.xml')
$lines | % { 
$elt = $dom.CreateElement("sentence")
$elt.set_InnerText($_)
$dom.root.AppendChild($elt)
}
$dom.Save('quotes.xml')

God I love this thing! Who needs perl anymore? Not me.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   Technology
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed
Comments are closed