Free XML to C++ Class Generator Online
Convert XML to C++ classes for pugixml and tinyxml2 instantly in your browser.
XML Input
C++ Output
What Is XML to C++?
You've got a SOAP WSDL, an RSS feed, or a game config XML — and your C++ project needs to model it. The problem: C++ has no built-in XML support, so you end up manually writing struct or class definitions. Libraries like pugixml (fast, header-only, MIT licensed) and tinyxml2 (tiny footprint, great for game engines) handle the actual parsing. But first you need the class definitions. This tool reads your XML structure and scaffolds C++ structs or classes that match your element hierarchy. The W3C XML specification defines the format; see also cppreference classes and W3C XML. All generation runs locally via DOMParser — nothing sent to a server.
How to Use This Tool
Paste or Upload XML
Paste XML or upload a file. Set class name, package, Data Class, and Nullable Types in the config.
Review C++ Output
The right panel shows generated structs/classes. Use pugixml or tinyxml2 to parse XML and populate.
Copy or Download
Use Copy or Download. For JSON to C++, use JSON to C++. For XML formatting, use XML Formatter.
When XML to C++ Helps
When building C++ apps that consume XML config, SOAP, or feeds, generate structs here. Use pugixml or tinyxml2 to parse. See cppreference for C++ docs.
Frequently Asked Questions
Which C++ XML library should I use — pugixml or tinyxml2?
pugixml is the fastest DOM-based parser available for C++ — it's header-only, MIT licensed, and the go-to for most projects. tinyxml2 has a smaller code footprint, making it ideal for game engines or resource-constrained apps. Both give you a tree to walk and populate your generated classes from. See the cppreference docs for more C++ detail.
How do I populate a C++ class from XML with pugixml?
Load your XML with pugi::xml_document doc; doc.load_string(xmlStr);, then call doc.child("root").child("field").child_value() to extract field values. Assign them to your generated class fields. For pugixml, there's no auto-deserialization — you write the mapping code once using the generated class as a guide.
Can I use this for SOAP WSDL-based XML responses?
Yes. Paste the body element of the SOAP XML response. The tool generates C++ classes matching the element structure. For full SOAP client generation, consider dedicated tools — but this gives you the data model to start with.
Should I use struct or class for XML data in C++?
Either works — they're almost identical in C++. The convention is to use struct for plain data containers (all members public by default) and class when you need encapsulation. Enable Data Class in the config to toggle between them.
Is my XML data sent to a server?
No. All generation runs locally in your browser via the DOMParser API. Nothing is uploaded or stored.
XML to C++ Examples
Here is an example of generating C++ structs from XML.
Example: Subscriber record
XML input:
Generated C++ output:
Related Tools
For C++ XML parsing, see pugixml and tinyxml2. For XML, see the W3C XML spec and W3C XML. For parsing in the browser, see MDN DOMParser. For C++, see cppreference. For JSON, see json.org.