# Julia code generation - from DTD or XML Schema to Julia struct

**URL:** <https://discourse.julialang.org/t/julia-code-generation-from-dtd-or-xml-schema-to-julia-struct/30952>\
**Category:** General Usage\
**Created:** [November 11, 2019, 1:53pm UTC](https://discourse.julialang.org/t/julia-code-generation-from-dtd-or-xml-schema-to-julia-struct/30952 "2019-11-11T13:53:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scelles](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scelles/32/220408_2.png) [@scelles](https://discourse.julialang.org/u/scelles)\
**Post date:** [November 11, 2019, 1:53pm UTC](https://discourse.julialang.org/t/julia-code-generation-from-dtd-or-xml-schema-to-julia-struct/30952/1 "2019-11-11T13:53:10Z")

</div>

Hello,

I have some XML data.

Most of these data have a schema to describe them.

Those schema is either a [Document type definition (DTD)](https://en.wikipedia.org/wiki/Document_type_definition) or an [XML Schema (xsd)](https://en.wikipedia.org/wiki/XML_Schema_(W3C))).

I wonder if Julia have a similar tool than Java JAXB `xjc` cli tool.

Go have similar tools  
xsdgen [xsdgen package - aqwari.net/xml/xsdgen - Go Packages](https://godoc.org/aqwari.net/xml/xsdgen)  
go-xsd [https://github.com/metaleap/go-xsd](https://github.com/metaleap/go-xsd)

I can manually convert these schema to Julia code but that’s a quite long and uninteresting task. So if a Julia library could scaffold some Julia code that will be a great feature.

Any suggestion?

Kind regards

---

<div class="post-metadata">

**Author:** ![Amin\_Yahyaabadi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amin_yahyaabadi/32/9826_2.png) [@Amin\_Yahyaabadi](https://discourse.julialang.org/u/Amin_Yahyaabadi)\
**Post date:** [November 11, 2019, 2:54pm UTC](https://discourse.julialang.org/t/julia-code-generation-from-dtd-or-xml-schema-to-julia-struct/30952/2 "2019-11-11T14:54:11Z")

</div>

That is similar to what I did in AcuteML:

> **[GitHub - aminya/AcuteML.jl: Acute Markup Language - HTML/XML in Julia](https://github.com/aminya/AcuteML.jl)**
>
> Acute Markup Language - HTML/XML in Julia. Contribute to aminya/AcuteML.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![scelles](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scelles/32/220408_2.png) [@scelles](https://discourse.julialang.org/u/scelles)\
**Post date:** [November 12, 2019, 8:24am UTC](https://discourse.julialang.org/t/julia-code-generation-from-dtd-or-xml-schema-to-julia-struct/30952/3 "2019-11-12T08:24:13Z")

</div>

Thanks @Amin_Yahyaabadi for pointing to your project but I don’t see how to use it with xsd (XML Schema).

You can see an example of such data schema at  
[GPX 1.1 Schema Documentation](http://www.topografix.com/GPX/1/1/) (documentation)  
[https://www.topografix.com/gpx/1/1/gpx.xsd](https://www.topografix.com/gpx/1/1/gpx.xsd) (xsd file)

---

<div class="post-metadata">

**Author:** ![Amin\_Yahyaabadi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amin_yahyaabadi/32/9826_2.png) [@Amin\_Yahyaabadi](https://discourse.julialang.org/u/Amin_Yahyaabadi)\
**Post date:** [November 12, 2019, 8:34am UTC](https://discourse.julialang.org/t/julia-code-generation-from-dtd-or-xml-schema-to-julia-struct/30952/4 "2019-11-12T08:34:11Z")

</div>

You can use AcuteML to generte any complex XML, HTLM file. You don’t need to be restricted to the functionality that XSD provides when you can use Julia code!

AcuteML has elements with [custom value checking](https://aminya.github.io/AcuteML.jl/dev/valueChecking/) (instead of the limited choice element in XSD), custom scalar or vector Julia types, custom defined Julia types (instead of the limited XSD types).

See this example: [https://github.com/aminya/AcuteML.jl#example---struct-definition](https://github.com/aminya/AcuteML.jl#example---struct-definition)

Also, you can check my MusicXML.jl: [https://github.com/JuliaMusic/MusicXML.jl/blob/a8841bf8d2e994c51797f6f3e093ab1071c14395/src/MusicXML.jl#L50](https://github.com/JuliaMusic/MusicXML.jl/blob/a8841bf8d2e994c51797f6f3e093ab1071c14395/src/MusicXML.jl#L50)

If you have a specific example, I can help you to use AcuteML for it.  
Also, open issues for any feature that you think is missing, so I can help you with it.
