XML Input

Ruby Output

What Is XML to Ruby?

Manually writing Ruby models from an XML feed means hours of typing attr_accessor for every field — and that gets tedious fast. Ruby has two great XML libraries: REXML, which ships with the standard library, and Nokogiri, which is faster and supports XPath. This tool scaffolds the class skeleton so you just fill in the parsing logic. The W3C XML specification defines the format, and everything runs in your browser via the DOMParser API. Nothing leaves your machine.

How to Use This Tool

1

Paste or Upload XML

Paste XML or upload a file. Set class name and package (module) in the config.

2

Review Ruby Output

The right panel shows generated classes. Use REXML or Nokogiri to parse and populate.

3

Copy or Download

Use Copy or Download. For JSON to Ruby, use JSON to Ruby. For XML formatting, use XML Formatter.

When XML to Ruby Helps

When building Rails apps that consume SOAP, RSS, or XML APIs, generate typed classes here. Use REXML (standard library) or Nokogiri for parsing.

Frequently Asked Questions

REXML vs Nokogiri — which should I use?

REXML ships with Ruby's standard library, so no extra gem needed. Nokogiri is significantly faster, supports XPath and CSS selectors, and handles malformed HTML. For production Rails apps with large XML feeds, Nokogiri is the standard choice.

How do I parse XML into the generated class with Nokogiri?

Use Nokogiri::XML(File.read("file.xml")) to load the document, then call .at_xpath or .css on the document to extract values and assign them to your class attributes.

Can I use these classes in a Rails API?

Yes. The generated classes work as plain Ruby objects. In a Rails controller, parse the incoming XML with Nokogiri and populate your class. They integrate easily with ActiveModel if you include the module.

Is my XML data sent to a server?

No. All processing runs locally in your browser using the DOMParser API. Nothing is uploaded or stored anywhere.

XML to Ruby Examples

Here is an example of generating Ruby classes from XML.

Example: Subscriber record

XML input:

Input

Generated Ruby output:

Output

Related Tools

For Ruby XML parsing, see REXML and Nokogiri. For XML, see the W3C XML spec and W3C XML. For parsing in the browser, see MDN DOMParser. For JSON, see json.org.