XML Input

Scala Output

What the generator writes

Paste an XML document and you get one final case class per element name. Attributes and child elements become constructor parameters, with a comment next to each one naming the XML it came from. Case classes give you equality, copy and pattern matching for free.

Repeated elements become List[T] = Nil. Fields that are missing in some records become Option[T] = None, and a type that nests itself (categories inside categories) always uses Option. Whole numbers become Int or Long, decimals Double, and true/false Boolean. Names that are Scala keywords, such as type, are wrapped in backticks.

The classes describe the data; they do not parse it. With scala-xml you would map each class in a few lines ((node \ "weightKg").text.toDouble). The output compiles with Scala 2.13 and 3. It is generated in your browser and the XML is not uploaded.

How to use it

Paste, set the package, copy.

1

Paste a sample

Paste XML into XML Input or Upload a file. Include a repeated element twice so it turns into a List. Sample loads a shipment:


  2.4
  11.0true

If the panel reports a parse error, the XML Validator shows the exact line.

2

Choose the package and Option handling

Root class renames the top-level case class (empty uses the root element name). Package sets the package line; clear it for none. Option[T] for missing fields controls whether optional fields are wrapped; with it off they become plain fields.

3

Copy or download

Download saves a .scala file named after the root class. Copy puts it on the clipboard.

Where it helps

Data pipelines

Spark or Akka jobs that ingest XML exports get typed records to work with instead of passing NodeSeq around.

Integrations

Logistics, banking and healthcare partners still send XML. Case classes make the contract explicit in code review.

Tests and fixtures

Build expected values with case class constructors and compare them against what your parser produced.

Learning a new format

Generating classes from a sample is a fast way to see every field a document can carry, including the optional ones.

Common questions

Does it generate parsing code?

No, only case classes. Mapping XML onto them takes a few lines with scala-xml or whichever XML library you already use.

Which Scala versions does it work with?

The output uses only basic syntax: case classes, default parameter values, List and Option. It compiles with Scala 2.13 and Scala 3.

How are attributes handled?

Each attribute becomes a parameter, the same as a child element. If an element has attributes and text, the text becomes a value parameter.

How are types chosen?

From the values in your sample. Whole numbers become Int, or Long when they do not fit, decimals Double, and true/false Boolean. Values with a leading zero stay String.

Why are some names in backticks?

XML names like type or class are Scala keywords. Backticks let you keep the same name without renaming the field.

Is the XML uploaded?

No. The page parses it in your browser. Inputs over 256 KB are rejected.

Related tools

Other converters that pair well with this one: