XML remains prevalent in enterprise systems, configuration files, and data exchange formats. This drill teaches you to parse XML documents, navigate nested elements, extract attributes and text content, and transform data structures. You'll learn REXML library usage, XPath-like navigation, attribute handling, and data transformation—essential skills for integrating with legacy systems, parsing config files, and building data pipelines.
REXML::Document.new(xml_string) parses XML
doc.elements.each('path/to/element') iterates over matching elements
element.attributes['name'] gets attribute value
element.text gets text content between tags
Use 'next unless condition' to filter elements
Hash.new { |h, k| h[k] = [] } creates hash with array defaults
array.sort_by! { |item| item[:key] } sorts array in place
hash.keys.sort sorts environment names alphabetically
parse_server_config('servers.xml')
SERVER CONFIGURATION REPORT ================================================== Environment: production web-prod-01 - 192.168.1.10:8080 web-prod-02 - 192.168.1.11:8080 Environment: staging db-stage-01 - 10.0.1.20:5432 web-stage-01 - 10.0.1.10:8080 -------------------------------------------------- Total Active Servers: 4 Environments: 2
parse_server_config('servers.xml')
SERVER CONFIGURATION REPORT ================================================== Environment: development dev-api - 127.0.0.1:3000 dev-cache - 127.0.0.1:6379 dev-db - 127.0.0.1:5432 -------------------------------------------------- Total Active Servers: 3 Environments: 1
parse_server_config('servers.xml')
SERVER CONFIGURATION REPORT ================================================== (No active servers found) -------------------------------------------------- Total Active Servers: 0 Environments: 0
Console output will appear here...
Are you sure?
You're making great progress