# XML Modeling

The code generator supports processing xml documents directly. That means even without a schema you can easily create at the very least an initial draft of your models just from samples. If you use a directory with multiple samples the transformer will merge and flatten duplicate classes, fields and field types.

    $ xsdata --package tests.fixtures.artists tests/fixtures/artists

Sample #1

    <metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
      <artist id="1f9df192-a621-4f54-8850-2c5373b7eac9" type="Person" type-id="b6e035f4-3ce9-331c-97df-83397230b0df">
        <name>Ludwig van Beethoven</name>
        <sort-name>Beethoven, Ludwig van</sort-name>
        <disambiguation>German composer</disambiguation>
        <ipi>00002507239</ipi>
        <ipi-list>
          <ipi>00002507239</ipi>
        </ipi-list>
        <isni-list>
          <isni>0000000121268987</isni>
        </isni-list>
        <gender id="36d3d30a-839d-3eda-8cb3-29be4384e4a9">Male</gender>
        <country>DE</country>
        <area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad">
          <name>Germany</name>
          <sort-name>Germany</sort-name>
          <iso-3166-1-code-list>
            <iso-3166-1-code>DE</iso-3166-1-code>
          </iso-3166-1-code-list>
        </area>
        <begin-area id="b86b7e97-c4e2-4ec2-942b-5a6cd8eea1da">
          <name>Bonn</name>
          <sort-name>Bonn</sort-name>
        </begin-area>
        <end-area id="afff1a94-a98b-4322-8874-3148139ab6da">
          <name>Wien</name>
          <sort-name>Wien</sort-name>
          <iso-3166-2-code-list>
            <iso-3166-2-code>AT-9</iso-3166-2-code>
          </iso-3166-2-code-list>
        </end-area>
        <life-span>
          <begin>1770-12-17</begin>
          <end>1827-03-26</end>
          <ended>true</ended>
        </life-span>
        <alias-list count="31">
          <alias sort-name="Beethoven" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc">Beethoven</alias>
          <alias sort-name="Beethoven _ Ludwig Van">Beethoven _ Ludwig Van</alias>
          <alias sort-name="Beethoven, Ludwig">Beethoven, Ludwig</alias>
          <alias sort-name="Beethoven, Ludwig Van">Beethoven, Ludwig Van</alias>
          <alias sort-name="Beethoven, Ludwig Van (1770 - 1827)">Beethoven, Ludwig Van (1770 - 1827)</alias>
          <alias sort-name="Beethoven, Ludwig Von">Beethoven, Ludwig Von</alias>
          <alias sort-name="Beethoven, Ludwig van (1770-1827)">Beethoven, Ludwig van (1770-1827)</alias>
          <alias sort-name="Beethoven, Ludwig van, 1770-1827">Beethoven, Ludwig van, 1770-1827</alias>
          <alias sort-name="Bethoveen" type="Search hint" type-id="1937e404-b981-3cb7-8151-4c86ebfc8d8e">Bethoveen</alias>
          <alias sort-name="L v Beethoven">L v Beethoven</alias>
          <alias locale="lv" sort-name="Bēthovens, L. Van">L. Van Bēthovens</alias>
          <alias sort-name="Beethoven, L. Von">L. Von Beethoven</alias>
          <alias sort-name="Beethoven, L. van">L. van Beethoven</alias>
          <alias locale="en" sort-name="Beethoven, L.Van">L.Van Beethoven</alias>
          <alias sort-name="Beethoven, Ludvig Von">Ludvig Von Beethoven</alias>
          <alias sort-name="Beethoven, Ludvig van">Ludvig van Beethoven</alias>
          <alias locale="lv" sort-name="Ludvigs van Bēthovens" primary="primary">Ludvigs van Bēthovens</alias>
          <alias sort-name="Beethoven, Ludwid van">Ludwid van Beethoven</alias>
          <alias sort-name="Beethoven, Ludwig">Ludwig Beethoven</alias>
          <alias sort-name="Beethoven, Ludwig Van (1770-1827)">Ludwig Van Beethoven (1770-1827)</alias>
          <alias sort-name="Beethoven, Ludwig Von">Ludwig Von Beethoven</alias>
          <alias locale="en" sort-name="Beethoven, Ludwig van" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc" primary="primary">Ludwig van Beethoven</alias>
          <alias sort-name="LvB" type="Search hint" type-id="1937e404-b981-3cb7-8151-4c86ebfc8d8e">LvB</alias>
          <alias sort-name="bheetoven" type="Search hint" type-id="1937e404-b981-3cb7-8151-4c86ebfc8d8e">bheetoven</alias>
          <alias sort-name="Beethoven, Ludwig van" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc">van Beethoven, Ludwig</alias>
          <alias locale="ru" sort-name="Beethoven">Бетховен</alias>
          <alias locale="ru" sort-name="Бетховен, Л." type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc">Л. Бетховен</alias>
          <alias locale="ja" sort-name="ベートーヴェン" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc" primary="primary">ベートーヴェン</alias>
          <alias locale="ja" sort-name="ベートーヴェン ルートヴィヒヴァン" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc">ルートヴィヒ・ヴァン・ベートーヴェン</alias>
          <alias locale="zh_Hant" sort-name="bèi duō fēn" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc" primary="primary">貝多芬</alias>
          <alias locale="ko" sort-name="Beethoven">베토벤</alias>
        </alias-list>
      </artist>
    </metadata>

Sample #2

    <metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
      <artist id="66c662b6-6e2f-4930-8610-912e24c63ed1" type="Group" type-id="e431f5f6-b5d2-343d-8b36-72607fffb74b">
        <name>AC/DC</name>
        <sort-name>AC/DC</sort-name>
        <disambiguation>Australian hard rock band</disambiguation>
        <isni-list>
          <isni>000000012271298X</isni>
        </isni-list>
        <country>AU</country>
        <area id="106e0bec-b638-3b37-b731-f53d507dc00e">
          <name>Australia</name>
          <sort-name>Australia</sort-name>
          <iso-3166-1-code-list>
            <iso-3166-1-code>AU</iso-3166-1-code>
          </iso-3166-1-code-list>
        </area>
        <begin-area id="3f179da4-83c6-4a28-a627-e46b4a8ff1ed">
          <name>Sydney</name>
          <sort-name>Sydney</sort-name>
        </begin-area>
        <life-span>
          <begin>1973-11</begin>
        </life-span>
        <alias-list count="7">
          <alias sort-name="AC DC">AC DC</alias>
          <alias sort-name="AC-DC">AC-DC</alias>
          <alias sort-name="AC.DC">AC.DC</alias>
          <alias sort-name="AC?DC">AC?DC</alias>
          <alias sort-name="ACDC">ACDC</alias>
          <alias sort-name="AC\DC">AC\DC</alias>
          <alias sort-name="Ballbreaker">Ballbreaker</alias>
        </alias-list>
      </artist>
    </metadata>

Sample #3

    <metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
      <artist id="b95ce3ff-3d05-4e87-9e01-c97b66af13d4" type="Person" type-id="b6e035f4-3ce9-331c-97df-83397230b0df">
        <name>Eminem</name>
        <sort-name>Eminem</sort-name>
        <ipi>00354929235</ipi>
        <ipi-list>
          <ipi>00354929235</ipi>
          <ipi>00354929431</ipi>
        </ipi-list>
        <isni-list>
          <isni>0000000117699370</isni>
          <isni>0000000368611900</isni>
        </isni-list>
        <gender id="36d3d30a-839d-3eda-8cb3-29be4384e4a9">Male</gender>
        <country>US</country>
        <area id="489ce91b-6658-3307-9877-795b68554c98">
          <name>United States</name>
          <sort-name>United States</sort-name>
          <iso-3166-1-code-list>
            <iso-3166-1-code>US</iso-3166-1-code>
          </iso-3166-1-code-list>
        </area>
        <begin-area id="bfae8151-2ba2-4f8f-bf2e-8fc16ce352c6">
          <name>St. Joseph</name>
          <sort-name>St. Joseph</sort-name>
        </begin-area>
        <life-span>
          <begin>1972-10-17</begin>
        </life-span>
        <alias-list count="13">
          <alias sort-name="EMINƎM" type="Search hint" type-id="1937e404-b981-3cb7-8151-4c86ebfc8d8e">EMINƎM</alias>
          <alias sort-name="Em" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc">Em</alias>
          <alias locale="en" sort-name="Eminem" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc" primary="primary">Eminem</alias>
          <alias sort-name="EminemMusic" type="Search hint" type-id="1937e404-b981-3cb7-8151-4c86ebfc8d8e">EminemMusic</alias>
          <alias sort-name="M&amp;M" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc">M&amp;M</alias>
          <alias sort-name="M. Mathers" type="Search hint" type-id="1937e404-b981-3cb7-8151-4c86ebfc8d8e">M. Mathers</alias>
          <alias sort-name="Marshall B. Mathers III" type="Search hint" type-id="1937e404-b981-3cb7-8151-4c86ebfc8d8e">Marshall B. Mathers III</alias>
          <alias sort-name="Mathers, Marshall Bruce, III" type="Legal name" type-id="d4dcd0c0-b341-3612-a332-c0ce797b25cf">Marshall Bruce Mathers III</alias>
          <alias sort-name="Marshall Mathers III" type="Search hint" type-id="1937e404-b981-3cb7-8151-4c86ebfc8d8e">Marshall Mathers III</alias>
          <alias sort-name="Ominem">Ominem</alias>
          <alias sort-name="Slim Shady" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc">Slim Shady</alias>
          <alias sort-name="The Real Slim Shady">The Real Slim Shady</alias>
          <alias locale="ja" sort-name="エミネム" type="Artist name" type-id="894afba6-2816-3c24-8072-eadb66bd04bc" primary="primary">エミネム</alias>
        </alias-list>
      </artist>
    </metadata>

Output

    from dataclasses import dataclass, field
    from typing import List, Optional, Union
    from xsdata.models.datatype import XmlDate, XmlPeriod

    __NAMESPACE__ = "http://musicbrainz.org/ns/mmd-2.0#"

    @dataclass
    class Alias:
        class Meta:
            name = "alias"
            namespace = "http://musicbrainz.org/ns/mmd-2.0#"

        locale: Optional[str] = field(
            default=None,
            metadata={
                "type": "Attribute",
            },
        )
        sort_name: Optional[str] = field(
            default=None,
            metadata={
                "name": "sort-name",
                "type": "Attribute",
                "required": True,
            },
        )
        type_value: Optional[str] = field(
            default=None,
            metadata={
                "name": "type",
                "type": "Attribute",
            },
        )
        type_id: Optional[str] = field(
            default=None,
            metadata={
                "name": "type-id",
                "type": "Attribute",
            },
        )
        primary: Optional[str] = field(
            default=None,
            metadata={
                "type": "Attribute",
            },
        )
        value: str = field(
            default="",
            metadata={
                "required": True,
            },
        )

    @dataclass
    class BeginArea:
        class Meta:
            name = "begin-area"
            namespace = "http://musicbrainz.org/ns/mmd-2.0#"

        id: Optional[str] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )
        name: Optional[str] = field(
            default=None,
            metadata={
                "type": "Element",
                "required": True,
            },
        )
        sort_name: Optional[str] = field(
            default=None,
            metadata={
                "name": "sort-name",
                "type": "Element",
                "required": True,
            },
        )

    @dataclass
    class Gender:
        class Meta:
            name = "gender"
            namespace = "http://musicbrainz.org/ns/mmd-2.0#"

        id: Optional[str] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )
        value: str = field(
            default="",
            metadata={
                "required": True,
            },
        )

    @dataclass
    class IpiList:
        class Meta:
            name = "ipi-list"
            namespace = "http://musicbrainz.org/ns/mmd-2.0#"

        ipi: List[str] = field(
            default_factory=list,
            metadata={
                "type": "Element",
                "min_occurs": 1,
            },
        )

    @dataclass
    class IsniList:
        class Meta:
            name = "isni-list"
            namespace = "http://musicbrainz.org/ns/mmd-2.0#"

        isni: List[str] = field(
            default_factory=list,
            metadata={
                "type": "Element",
                "min_occurs": 1,
            },
        )

    @dataclass
    class Iso31661CodeList:
        class Meta:
            name = "iso-3166-1-code-list"
            namespace = "http://musicbrainz.org/ns/mmd-2.0#"

        iso_3166_1_code: Optional[str] = field(
            default=None,
            metadata={
                "name": "iso-3166-1-code",
                "type": "Element",
                "required": True,
            },
        )

    @dataclass
    class Iso31662CodeList:
        class Meta:
            name = "iso-3166-2-code-list"
            namespace = "http://musicbrainz.org/ns/mmd-2.0#"

        iso_3166_2_code: Optional[str] = field(
            default=None,
            metadata={
                "name": "iso-3166-2-code",
                "type": "Element",
                "required": True,
            },
        )

    @dataclass
    class LifeSpan:
        class Meta:
            name = "life-span"
            namespace = "http://musicbrainz.org/ns/mmd-2.0#"

        begin: Optional[Union[XmlDate, XmlPeriod]] = field(
            default=None,
            metadata={
                "type": "Element",
                "required": True,
            },
        )
        end: Optional[XmlDate] = field(
            default=None,
            metadata={
                "type": "Element",
            },
        )
        ended: Optional[bool] = field(
            default=None,
            metadata={
                "type": "Element",
            },
        )

    @dataclass
    class AliasList:
        class Meta:
            name = "alias-list"
            namespace = "http://musicbrainz.org/ns/mmd-2.0#"

        count: Optional[int] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )
        alias: List[Alias] = field(
            default_factory=list,
            metadata={
                "type": "Element",
                "min_occurs": 1,
            },
        )

    @dataclass
    class Area:
        class Meta:
            name = "area"
            namespace = "http://musicbrainz.org/ns/mmd-2.0#"

        id: Optional[str] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )
        name: Optional[str] = field(
            default=None,
            metadata={
                "type": "Element",
                "required": True,
            },
        )
        sort_name: Optional[str] = field(
            default=None,
            metadata={
                "name": "sort-name",
                "type": "Element",
                "required": True,
            },
        )
        iso_3166_1_code_list: Optional[Iso31661CodeList] = field(
            default=None,
            metadata={
                "name": "iso-3166-1-code-list",
                "type": "Element",
                "required": True,
            },
        )

    @dataclass
    class EndArea:
        class Meta:
            name = "end-area"
            namespace = "http://musicbrainz.org/ns/mmd-2.0#"

        id: Optional[str] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )
        name: Optional[str] = field(
            default=None,
            metadata={
                "type": "Element",
                "required": True,
            },
        )
        sort_name: Optional[str] = field(
            default=None,
            metadata={
                "name": "sort-name",
                "type": "Element",
                "required": True,
            },
        )
        iso_3166_2_code_list: Optional[Iso31662CodeList] = field(
            default=None,
            metadata={
                "name": "iso-3166-2-code-list",
                "type": "Element",
                "required": True,
            },
        )

    @dataclass
    class Artist:
        class Meta:
            name = "artist"
            namespace = "http://musicbrainz.org/ns/mmd-2.0#"

        id: Optional[str] = field(
            default=None,
            metadata={
                "type": "Attribute",
                "required": True,
            },
        )
        type_value: Optional[str] = field(
            default=None,
            metadata={
                "name": "type",
                "type": "Attribute",
                "required": True,
            },
        )
        type_id: Optional[str] = field(
            default=None,
            metadata={
                "name": "type-id",
                "type": "Attribute",
                "required": True,
            },
        )
        name: Optional[str] = field(
            default=None,
            metadata={
                "type": "Element",
                "required": True,
            },
        )
        sort_name: Optional[str] = field(
            default=None,
            metadata={
                "name": "sort-name",
                "type": "Element",
                "required": True,
            },
        )
        disambiguation: Optional[str] = field(
            default=None,
            metadata={
                "type": "Element",
            },
        )
        ipi: Optional[str] = field(
            default=None,
            metadata={
                "type": "Element",
            },
        )
        ipi_list: Optional[IpiList] = field(
            default=None,
            metadata={
                "name": "ipi-list",
                "type": "Element",
            },
        )
        isni_list: Optional[IsniList] = field(
            default=None,
            metadata={
                "name": "isni-list",
                "type": "Element",
                "required": True,
            },
        )
        gender: Optional[Gender] = field(
            default=None,
            metadata={
                "type": "Element",
            },
        )
        country: Optional[str] = field(
            default=None,
            metadata={
                "type": "Element",
                "required": True,
            },
        )
        area: Optional[Area] = field(
            default=None,
            metadata={
                "type": "Element",
                "required": True,
            },
        )
        begin_area: Optional[BeginArea] = field(
            default=None,
            metadata={
                "name": "begin-area",
                "type": "Element",
                "required": True,
            },
        )
        end_area: Optional[EndArea] = field(
            default=None,
            metadata={
                "name": "end-area",
                "type": "Element",
            },
        )
        life_span: Optional[LifeSpan] = field(
            default=None,
            metadata={
                "name": "life-span",
                "type": "Element",
                "required": True,
            },
        )
        alias_list: Optional[AliasList] = field(
            default=None,
            metadata={
                "name": "alias-list",
                "type": "Element",
                "required": True,
            },
        )

    @dataclass
    class Metadata:
        class Meta:
            name = "metadata"
            namespace = "http://musicbrainz.org/ns/mmd-2.0#"

        artist: Optional[Artist] = field(
            default=None,
            metadata={
                "type": "Element",
                "required": True,
            },
        )