Category: Ruby

Ruby – Parse XML or Build XML

By polfilm,

To parse an XML string:

require 'xml'

xml = '<?xml version="1.0"?><root><child attr="value">text</child></root>'
root = XML::Parser.string(xml).parse.root
child = root.children.find { |node| == "child" }
attr = child["attr"]

To build an XML document:

require 'xml'

xml =
root ="root")
child ="child", "text")
child["attr"] = "value"
root << child

Chef Solo Pattern with Berkshelf

By polfilm,
Chef – berkshelf lesson for dummies like me Ermahgerd!