Perl to XML Converter
Paste Perl packages or data structures. Get clean XML back.
Input
Output
Paste your Perl code on the left and press Convert.
Or drop a file on this box, , or .
What this tool does
Plenty of Perl still sits between a database and some partner who wants XML: a nightly batch, a SOAP::Lite client, a CGI script nobody dares touch. Writing the expected payload by hand means reading every sub new, remembering which keys hold array refs, and guessing what XML::Simple would have done with ForceArray switched on. Paste the packages and the code that calls ->new(...), and our converter returns an XML document whose root is named after the package and whose children follow the hash keys of the blessed object.
The converter follows the usual Perl OO idioms. A constructor that runs bless $self, $class over a hash ref produces an element per package, with the hash keys as children. Array refs are wrapped in an element named after their key, and each entry inside gets an element of its own. Nested hash refs nest. undef is kept as an empty element, and keys written in the -name style that XML::Simple treats as attributes can come out as attributes, which keeps the result close to what XML::Simple or XML::LibXML would build.
You can paste multiple package blocks at once, package Order; package OrderItem; package Address;, and each one comes through with its constructor-assigned fields expanded. Plain non-OO data structures work too: feed in my $data = { ... }; and the tool walks the refs, preserving hash keys as element names. For the deeper Perl rules behind all this, the official perldoc is the reference.
How to use it
Load Sample and Convert are the only two controls, so this is quick. Here is what each step does with Perl input.
Paste your Perl (or load the sample)
Drop the code into the left editor as-is. A package with a constructor, a plain hash ref, nested packages, or a mix: all fine. Hit Load Sample to see a realistic example first.
use strict;, use warnings;, POD blocks and # comments can all stay. The converter looks at the hash refs being blessed and the arguments passed to the constructors; subroutine bodies that only compute things are passed over.
Hit Convert
Hit the green Convert button. The Perl goes to our backend, which follows each bless $self, $class back to its package, fills in the values from the Order->new(...) call and sends the XML back. A "Converting..." overlay sits on the editors until the response arrives.
Copy the XML
Read the result in the right pane. Hash keys keep their Perl spelling, underscores and all; nothing is camel-cased. Copy it into the fixture your Test::More suite loads, or into the body of the SOAP call, and run it through the XML Validator if the receiving side is strict.
When this actually comes in handy
Feeding XML::LibXML or XML::Simple
You have a Perl data structure and want to see exactly what it looks like as XML before wiring up XMLout / XML::LibXML::Document. Paste, convert, copy, compare.
Legacy system integration
A CPAN-backed integration still expects SOAP 1.1 or a bespoke XML format. Paste your Perl representation and get a realistic body to hand to SoapUI or curl.
Migrating away from Perl
Replacing an old Perl service with something else? Export the data shape as XML first: it is the neutral ground for porting to Python, Java, or C#.
Docs that match the code
Generate XML examples for a MetaCPAN module README or an internal wiki straight from your actual packages, so the docs do not drift.
Common questions
Can I paste multiple packages at once?
Yes. Paste a whole .pm file or several package blocks stacked together. Each package comes through with its constructor-assigned hash keys expanded and nested object refs resolved. If Order holds an array ref of OrderItem objects and a shipping_address hash ref, all three land in the output.
How does it handle undef and missing keys?
A key whose value is undef becomes an empty element so the XML shape stays stable across instances. Keys that are missing entirely from the hash are omitted. Array refs with empty arrays become empty container elements (<items></items>) rather than being dropped.
Do array refs and hash refs work the same way?
An array ref gets a wrapper element named after its hash key. Inside it, each entry appears as its own element: a blessed OrderItem object is written as <OrderItem>, while plain scalars fall back to a generic <Item> tag. A hash ref simply nests, one child per key, and keys that are not legal XML names have the bad characters replaced. Arrays of hash refs and hashes of arrays are handled the same way at every depth.
What about blessed references and multiple inheritance?
Blessed references keep their class name available: it can be used as the element tag when it makes sense. For multi-inheritance via @ISA or Moose/Moo roles, the attributes on the final composed object come through; we do not try to reconstruct the inheritance graph in XML.
Is my code stored?
Only for the length of one request. Convert ships the Perl to our backend, the reply carries the XML, and no copy is kept on the site. Perl scripts often carry DSNs and passwords in my $dbh = DBI->connect(...) lines, so replace those with dummies before pasting.
What if the Perl uses subroutine refs or tie?
A key that points at a sub { ... } or a tied hash has no data the converter can read, so it is written as an empty element and the rest of the structure still comes out. Values computed at runtime (a localtime call, a DB lookup) cannot be evaluated either, so put a literal in the constructor call if you need a real value. And if perl -c complains about your file, sort that out before converting; badly broken syntax gives the converter little to go on.
Other tools you may need
The XML from a Perl hash rarely ends the job. These help you check it, reshape it, or produce the JSON version of the same object: