tefra / xsdata

Naive XML & JSON Bindings for python
https://xsdata.readthedocs.io
MIT License
325 stars 59 forks source link

Element containing only #PCDATA isn't generated [at repo head 2023-02-26] #758

Closed RobertBaruch closed 1 year ago

RobertBaruch commented 1 year ago

Using repo head.

An element that contains only #PCDATA isn't generated:

test.dtd:

<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT kap (ofc)>
<!ELEMENT ofc (#PCDATA)>

Generate:

$ xsdata generate test.dtd

Result:

from dataclasses import dataclass, field
from typing import Optional

@dataclass
class Kap:
    class Meta:
        name = "kap"

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

This doesn't seem correct, since ofc should become a class.

Note that if I remove kap from the DTD so that there's only ofc, I get this:

from dataclasses import dataclass, field

@dataclass
class Ofc:
    class Meta:
        name = "ofc"

    value: str = field(
        default="",
        metadata={
            "required": True,
        }
    )

That is the expected class. I'm not sure why the Ofc class is missing from the first test file.

tefra commented 1 year ago

xsdata philosophy is to produce the simplest possible classes, that means simple content classes are flattened by default

RobertBaruch commented 1 year ago

Good to know!