XML Input

PHP Output

What Is XML to PHP?

Anyone who has tried to parse a SOAP API response or an RSS feed in PHP knows the pain — you get a blob of XML and then manually write class properties one by one. This tool reads your XML document and generates a matching PHP class instantly, with optional typed properties (PHP 7.4+). You can add a namespace for Laravel or Symfony projects, then use SimpleXML or DOMDocument to populate it. Everything runs in the browser — nothing is sent to a server, so it is safe for production or internal XML.

How to Use This Tool

1

Paste or Upload XML

Paste XML or upload a file. Set class name, namespace, and Typed Properties in the config.

2

Review PHP Output

The right panel shows generated classes. Use SimpleXML or DOMDocument to parse and populate.

3

Copy or Download

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

XML to PHP Examples

Here is an example of generating PHP classes from XML.

Example: Subscriber record

XML input:

Input

Generated PHP output:

Output

When XML to PHP Helps

When building Laravel or Symfony apps that consume SOAP APIs, RSS feeds, or XML config, generate typed classes here. Use SimpleXML or DOMDocument to parse and populate.

Frequently Asked Questions

SimpleXML vs DOMDocument — which should I use?

SimpleXML is easier for read-only access to well-formed XML. DOMDocument supports full editing, XPath queries, and more complex structures. Both work with the classes this tool generates.

Does the generated PHP work with Laravel and Symfony?

Yes. You can set a namespace that matches your Laravel or Symfony app structure. The generated class is a plain PHP class — populate it after parsing with SimpleXML or DOMDocument.

Can I use typed properties in PHP 7.x?

Typed properties require PHP 7.4 or later. Disable the Typed Properties toggle if you are targeting an older version.

Is my XML sent to a server?

No. The class is generated entirely in your browser using JavaScript. No data leaves your machine, so it is safe for production XML, internal APIs, or sensitive config files.

What if my XML has nested elements?

Nested elements are reflected as nested classes or typed properties in the output. Review the generated code and adjust for deeply nested or repeated elements as needed.

Related Tools

For PHP XML parsing, see SimpleXML and DOMDocument. For XML, see the W3C XML spec and W3C XML. For parsing in the browser, see MDN DOMParser. For JSON, see json.org.