Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xsi:type not working on xsd:anyType elements #306

Closed
mihxil opened this issue Oct 26, 2020 · 7 comments
Closed

xsi:type not working on xsd:anyType elements #306

mihxil opened this issue Oct 26, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@mihxil
Copy link

mihxil commented Oct 26, 2020

I have a use case were we wrap lists of 'items' in an xml where the elements are in the xsd marked as 'xs:anyType'.

The xml though specifies the type with something like:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="api:searchResultItem"
so, the actual type is specified with an xsi:type attribute.

If I unmarshal this xml with xsdata these object just become AnyElements and are not unmarshaled to the correct type (as e.g. pyxb and jaxb would do).

I don't rule out that I do something wrong, but as far as I looked into the code it is not supported at all. But please correct me if I'm wrong.

@tefra tefra added the enhancement New feature or request label Oct 26, 2020
@tefra
Copy link
Owner

tefra commented Oct 26, 2020

Hi @mihxil

yes currently on xs:anyType derived fields there are no lookups in place to match the actual model even when an xsi:type is provided. The xsi:type lookup exists for fields with a known base type but not for wildcards yet.

Its a bit trickier for wildcards because the parser needs to scan the whole context to match any defined models that match the active qualified name, but it's definitely one of the next things I want to work on.

@tefra
Copy link
Owner

tefra commented Oct 26, 2020

I am sure I can find examples from the w3c suite but it would be great if you could share your schema and a sample xml.

@mihxil
Copy link
Author

mihxil commented Oct 29, 2020

I was just trying it out in a project that currently uses pyxb. Approximately at this line:
https://github.com/npo-poms/pyapi/blob/feature/xsdata/tests/unit/xml_test.py#L191
I became aware of the problem.

I'm sure that I can make up a simpler example though.

@tefra
Copy link
Owner

tefra commented Oct 29, 2020

thank you @mihxil it's perfect.

@tefra
Copy link
Owner

tefra commented Nov 6, 2020

@mihxil give it a try #310 I still want to tweak a few things but the xsi:type lookup should work for your case.

tefra added a commit to tefra/xsdata-w3c-tests that referenced this issue Nov 8, 2020
@tefra tefra closed this as completed in a78f001 Nov 10, 2020
tefra added a commit to tefra/xsdata-w3c-tests that referenced this issue Nov 10, 2020
@tefra
Copy link
Owner

tefra commented Nov 10, 2020

@mihxil I 've merged the updates to master, I have included your test case in samples repo as well.

Surprisingly the w3c test suite has only a few similar test cases but yours is extra interesting because of the different namespaces.

@mihxil
Copy link
Author

mihxil commented Nov 17, 2020

Thansk a lot. I'll take a further look as soon as I've some time!

tefra added a commit to tefra/xsdata-w3c-tests that referenced this issue Nov 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants