Closed CholoTook closed 3 months ago
I kept banging my head on this and finally solved all my problems :-)
What was confusing me about wrapped was the 'implied' element matching (using pydantic field names).
e.g. I was trying to write things like:
class Applicant(BaseXmlModel, nsmap=NSMAP):
sequence: str = attr(name="sequence")
data_format: str = attr(name="data-format")
applicant_name: Name = element(tag="applicant-name")
class Parties(BaseXmlModel, nsmap=NSMAP):
applicants: List[Applicant] = wrapped("applicant", element())
but the correct code is:
class Applicant(BaseXmlModel, nsmap=NSMAP):
sequence: str = attr(name="sequence")
data_format: str = attr(name="data-format")
applicant_name: Name = element(tag="applicant-name")
class Parties(BaseXmlModel, nsmap=NSMAP):
applicant: List[Applicant] = wrapped("applicants", element())
Many thanks again for the great project!
Hi, Thank you for the great product and the good documentation. After a lot of reading, I'm finally starting to get to grips with the code ;-)
The example shows things like
default_factory=list
down in the element... I'm having trouble making lists of elements under placeholders work (for some reason)...I'm wondering what I'm missing, and so I'm looking for docs about the default_factory...
https://pydantic-xml.readthedocs.io/en/latest/search.html?q=default_factory&check_keywords=yes&area=default
^^ A bit beyond me...
Here is an example of the XML I'd like to model:
Here is what I have so far (still not working, but getting closer...):