Closed dtam95 closed 3 months ago
Closing this issue as I've now got this working with the following model definition (there was no need to modify the nsmap
). I appear to have misunderstood the way namespacing inheritance works in xml.
class Bar(BaseXmlModel, ns="bar", nsmap={"": "https://foo.com", "bar": "https://bar.com"}):
multiplier: int = element(ns="")
value: int = element(ns="")
class Foo(BaseXmlModel, nsmap={"": "https://foo.com", "bar": "https://bar.com"}):
bar: Bar = element(tag="Bar")
Hi, I am relatively new to XML and
pydantic-xml
so am just after some support with deserializing the particular structure below. Apologies if this is detailed in the docs somewhere, I've tried and failed many times to find a solution for this.XML Being Parsed
Pydantic-xml Models
Problem
When I attempt to parse the XML using the above model definitions like so
I receive the following error:
However, if I explicitly define the namespace of the
Bar
elements like so, I am able to successfully parse the xmlCan anyone advise me where I am going wrong when attempting to parse the first XML structure?
I was under the impression that defining the elements of
Bar
aselement(ns="")
would allow the original XML structure to be parsed using the implicit namespace rather than needing it to be explicitly defined on all the elements.