Blogroll · Ruby · xml

Ruby Gem xml-simple

Code:

1. Create test.xml file Ex. D:\xml\test.xml

2. Copy the XML content from http://msdn.microsoft.com/en-us/library/windows/desktop/ms762271(v=vs.85).aspx and paste in to test.xml file

3. Install xml-simple library CMD — >gem install xml-simple

4. Create new Ruby File code.rb Ex. D:\xml\code.rb

require 'rubygems'
require 'xmlsimple'
config = XmlSimple.xml_in('test.xml', { 'KeyAttr' => 'name' })
i=0
while i < 12
puts config["book"][i]["id"]
puts config["book"][i]["title"]
puts config["book"][i]["author"]
puts "-----------------------"
i+=1
end

Output :

bk101
XML Developer’s Guide
Gambardella, Matthew
———————–
bk102
Midnight Rain
Ralls, Kim
———————–
bk103
Maeve Ascendant
Corets, Eva
———————–
bk104
Oberon’s Legacy
Corets, Eva
———————–
bk105
The Sundered Grail
Corets, Eva
———————–
bk106
Lover Birds
Randall, Cynthia
———————–
bk107
Splish Splash
Thurman, Paula
———————–
bk108
Creepy Crawlies
Knorr, Stefan
———————–
bk109
Paradox Lost
Kress, Peter
———————–
bk110
Microsoft .NET: The Programming Bible
O’Brien, Tim
———————–
bk111
MSXML3: A Comprehensive Guide
O’Brien, Tim
———————–
bk112
Visual Studio 7: A Comprehensive Guide
Galos, Mike
———————–

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s