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

Looking for help in enabling smarter models #853

Unanswered
mcbeth asked this question in Q&A
Discussion options

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.

You must be logged in to vote

Replies: 1 comment

Comment options

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

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

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