XML to Java Converter Online — Generate POJO Classes

Paste any XML and generate JAXB-annotated Java POJO classes. Attributes map to @XmlAttribute, elements to @XmlElement, and nested structures get their own classes — all in your browser.

What is an XML to Java converter?

An XML to Java converter takes a real XML document and emits annotated POJO classes that JAXB (or Jackson XML) can unmarshal into. The OpenFormatter generator inspects every element and attribute, infers Java types, and produces a complete class hierarchy with @XmlRootElement, @XmlElement, and @XmlAttribute annotations — saving the tedious step of writing them by hand for SOAP, RSS, or configuration XML.

XML differs from JSON in two ways your Java model has to honour. First, XML has attributes on elements (<book id="bk101">) — these become @XmlAttribute-annotated fields, not @XmlElement. Second, XML has namespaces; the generator strips them by default, but you can re-add them via the namespace argument on each annotation. Both aspects are handled by the sample below.

Sample XML and the Java POJO it generates

Input XML

<book id="bk101" lang="en">
  <title>Effective Java</title>
  <year>2018</year>
  <price currency="USD">45.99</price>
</book>

Generated Java

@XmlRootElement(name = "book")
@XmlAccessorType(XmlAccessType.FIELD)
public class Book {
    @XmlAttribute(name = "id")
    private String id;
    @XmlAttribute(name = "lang")
    private String lang;
    @XmlElement(name = "title")
    private String title;
    @XmlElement(name = "year")
    private int year;
    @XmlElement(name = "price")
    private Price price;
    // getters / setters
}

Notice id and lang use @XmlAttribute, while title and year use @XmlElement. The nested <price currency="USD">45.99</price> generates a Price class with one @XmlAttribute and one @XmlValue for the text content — exactly what JAXB expects.

How to convert XML to Java — 4 steps

  1. Paste your XML. A SOAP envelope body, an RSS feed entry, a Spring beans XML — anything well-formed.
  2. Click Convert. The browser parses the XML and generates JAXB-annotated POJO classes for the full element tree.
  3. Review attribute mapping. Confirm that @XmlAttribute annotations match the attributes you care about; tweak field names if needed.
  4. Drop into your project. Copy the output, save each class as its own .java file, and unmarshal real XML with JAXBContext.newInstance(Root.class).createUnmarshaller().unmarshal(reader).

JAXB Annotations

Generates @XmlRootElement on the top class plus @XmlElement and @XmlAttribute on every field — ready to unmarshal with JAXBContext.

Attribute vs Element

XML attributes become @XmlAttribute fields, child elements become @XmlElement fields. The distinction is preserved exactly so round-tripping is lossless.

Client-Side Only

Your XML — including SOAP responses with credentials — is parsed in JavaScript on your machine. Verify in DevTools: zero network requests on Convert.

Common use cases

  • check_circleGenerate JAXB POJO classes from a SOAP service response
  • check_circleBuild Java models for an RSS or Atom feed reader
  • check_circleConvert Spring beans XML configuration to typed POJOs
  • check_circleGenerate Java types from an XSD-described XML file
  • check_circleCreate Java unmarshalling models for legacy enterprise XML
  • check_circleBuild typed POJOs for a SAML or WS-Security XML payload
  • check_circleGenerate Java models for sitemaps.xml or robots.xml
  • check_circleCreate POJOs for Maven pom.xml-style build descriptors

Why client-side conversion matters

SOAP responses and enterprise XML often contain customer PII, API tokens, internal endpoint names, and database identifiers. Pasting them into a server-hosted converter is a compliance violation in most regulated industries. OpenFormatter parses the XML and generates Java code entirely in JavaScript on your device — no upload, no logs, no cookies. Open DevTools → Network and confirm no requests fire when you click Convert.

More XML tooling

Validate, format, or convert XML to other languages — every tool runs locally in your browser.

Frequently Asked Questions

JAXB or Jackson XML — which does the output target?

The generator emits JAXB annotations (@XmlRootElement, @XmlElement, @XmlAttribute, @XmlValue) since JAXB is the standard Java EE / Jakarta EE binding. The same POJO class can be reused with Jackson XML by adding @JacksonXmlRootElement and @JacksonXmlProperty(isAttribute = true) — Jackson is forgiving about extra annotations and will use whichever it understands.

How are XML attributes mapped to Java fields?

XML attributes (e.g. <book id="bk101">) become private fields annotated with @XmlAttribute(name = "id"). They are exposed via standard getter/setter methods. The attribute name is preserved exactly so JAXB unmarshalling round-trips correctly. Element values (<title>...</title>) instead receive @XmlElement.

Does the output use jakarta.xml.bind or javax.xml.bind?

The default import is jakarta.xml.bind.annotation.* for Jakarta EE 9+ and Spring Boot 3+. For Java EE 8 / Spring Boot 2 projects still on JAXB 2, change the import to javax.xml.bind.annotation.* — the annotation names are identical, only the package moved.

How are repeated elements like <tag> in <tags> represented?

Repeated child elements become a List<TagType> field on the parent class. JAXB automatically marshals and unmarshals the list against repeated <tag> elements when @XmlElement is present on the field.

What about XML namespaces?

The basic generator strips namespaces from element names and produces unqualified Java fields. For namespace-aware binding add namespace = "http://example.com/ns" to @XmlElement and @XmlRootElement, or use a package-info.java with @XmlSchema(namespace = ...) so JAXB applies it to every class in the package.

Can elements with both attributes and text content be modeled?

Yes. <price currency="USD">45.99</price> generates a class with two fields — currency annotated with @XmlAttribute and a value field annotated with @XmlValue. JAXB unmarshals the text content into the @XmlValue field while populating attributes separately.

Is the XML I paste sent to your servers?

No. XML is parsed by the browser DOMParser and the Java code is generated entirely in JavaScript on your machine. Open DevTools → Network and you will see no requests when you click Convert. Safe for SOAP responses and configuration files containing API keys or credentials.

How do I unmarshal XML into the generated POJOs?

Use JAXB Unmarshaller: JAXBContext ctx = JAXBContext.newInstance(Book.class); Book b = (Book) ctx.createUnmarshaller().unmarshal(new StringReader(xml)); — the annotated fields are populated automatically. For Spring Boot 3+ the same code works with the jakarta.xml.bind imports.

XML to Java Converter Online — Generate POJO Classes