Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add ID/IDREF support that is similar to JAXB #1221

pahjbo started this conversation in Ideas
Discussion options

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?

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /