-
-
Notifications
You must be signed in to change notification settings - Fork 79
-
I'm trying to figure out to put a little intelligence in my models so that the impedance mismatch between the xml and our internal classes is lessened.
Here is an example greatly simplified XSD
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name="TimeDelta"> <xsd:annotation> <xsd:documentation> Offset from Jan 1, 2000 00:00:00Z </xsd:documentation> </xsd:annotation> <xsd:attribute name="sec" type="xsd:unsignedInt" use="required"/> <xsd:attribute name="micros" type="xsd:unsignedInt" use="required"/> </xsd:complexType> <xsd:element name="Two"> <xsd:complexType> <xsd:sequence> <xsd:element name="Before" type="TimeDelta"/> <xsd:element name="After" type="TimeDelta"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>
If we pretend for a second to have a class that stores things in days instead
class MyClass: def __init__(self, days): self.days = days
I was hoping to put a shim in between the two objects so I could step between the two more cleanly
The Converter infrastructure appears to be for DATA rather than attributes.
I think my worst case is having to do something like
a = example.Two(before=MyClass(end).render_to_time_delta(), after=example.TimeDelta(sec=10, micros=100))
But, I'm hoping I can declare a type-mapping or converter or... so that I tell xsdata "when you see MyClass", always render that as TimeDelta. parsing is much less important, but still a consideration.
Thanks for your time.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
I'm also looking for ways to ensure that the xsd namespace always appears only in the root node and not on and sub-nodes, but that's a very different question
Beta Was this translation helpful? Give feedback.