-
-
Notifications
You must be signed in to change notification settings - Fork 79
-
It would be nice if the library could support ID and IDREF in the sense that JAXB can do with its @xmlid and @XmlIDREF where on serialization of an object tree, any field/attribute that is annotated as @XmlIDREF will emit just the field marked @xmlid from the child object (rather than the serializing the whole child object) and vice versa, on deserialising the referenced ID will be replaced with the whole child object wherever it appears. In xsdata it would seem natural to add similar xmlid and xmlidref (boolean) metadata items to the field part of the data model
>>> @dataclass
... class Child:
... id: str = field( metadata={"type": "Attribute", "required": True, "xmlid":True})
...
and
>>> @dataclass
... class Parent:
... ref: Child = field( metadata={"type": "Element", "required": True, "xmlidref":True})
...
At this point it should be relatively easy to alter the serialization to emit the ID, and rather less easy for the deserialisation where perhaps the most general thing to do would be to to double pass over the instantiated object tree to find the IDs and then to replace them with the actual objects.
Has anyone tried to implement this already, or has any improvements on the above ideas?
Beta Was this translation helpful? Give feedback.