Challenge

Problem

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.

Difficulty: Intermediate

Instructions

  1. Read XML configuration from servers.xml
  2. Parse XML document
  3. Extract server information:
    • hostname
    • ip_address (from 'ip' attribute)
    • port (from 'port' attribute)
    • status (from 'status' attribute)
    • environment (from parent 'environment' name attribute)
  4. Filter to only include servers where status='active'
  5. Group servers by environment
  6. Sort servers within each environment by hostname
  7. Print report:
    'SERVER CONFIGURATION REPORT'
    '=' * 50
    'Environment: [name]'
    ' [hostname] - [ip]:[port]'
    (blank line between environments)
  8. Print summary:
    '-' * 50
    'Total Active Servers: X'
    'Environments: Y'

Files

Editable
Read-only

Hints

Hint 1

REXML::Document.new(xml_string) parses XML

Hint 2

doc.elements.each('path/to/element') iterates over matching elements

Hint 3

element.attributes['name'] gets attribute value

Hint 4

element.text gets text content between tags

Hint 5

Use 'next unless condition' to filter elements

Hint 6

Hash.new { |h, k| h[k] = [] } creates hash with array defaults

Hint 7

array.sort_by! { |item| item[:key] } sorts array in place

Hint 8

hash.keys.sort sorts environment names alphabetically

Provided Files (Read-only)

1. Multiple environments with active and inactive servers

Input:
parse_server_config('servers.xml')
Expected Output:
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

2. Single environment all active

Input:
parse_server_config('servers.xml')
Expected Output:
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

3. All servers inactive

Input:
parse_server_config('servers.xml')
Expected Output:
SERVER CONFIGURATION REPORT
==================================================
(No active servers found)

--------------------------------------------------
Total Active Servers: 0
Environments: 0
+ 2 hidden test cases