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

Use proper NULL value when we wanna use with XSD #225

Merged
merged 1 commit into from
Nov 8, 2023

Conversation

radeno
Copy link
Contributor

@radeno radeno commented Nov 5, 2023

When XML is validated against XSD with nullable=true definition then PHP NULL should be converted to proper XML value.

<element></element> or <element/> is parsed always as empty string. When field is missing then it is not defined. So when value is null, we should provide proper information to XML parsers.

Reference: https://www.w3.org/TR/xmlschema-0/#Nils

Output validated against: https://jsonformatter.org/xml-viewer/a0b80a
XML output converted to XSD schema: https://www.liquid-technologies.com/online-xml-to-xsd-converter

There is a chance that simpler XML parsers could consider xsi:nil="true" still as string

@freekmurze freekmurze merged commit 8267281 into spatie:main Nov 8, 2023
7 checks passed
@freekmurze
Copy link
Member

Thanks!

@radeno radeno deleted the Use-proper-NULL-value branch November 9, 2023 11:48
@SanderMuller
Copy link

@radeno & @freekmurze
This is a breaking change for my application, the API we talk to starting giving errors after this version bump. I tried to see how I could update my code to make it work again, but don't immediately see what change to make to either get non null values or to get the API we talk to to be happy.

Error response from the API:
If the 'nillable' attribute is false in the schema, the 'xsi:nil' attribute must not be present in the instance.

For now I locked this package on the previous release as a temp workaround.

@freekmurze
Copy link
Member

@radeno Can you take a look at this problem?

@tw99
Copy link

tw99 commented Nov 13, 2023

This is a breaking change in our codebase as well. We validate our generated XML against an XSD spec using DOMDocument::schemaValidateSource()

<xsd:element name="address2" type="simpleType.Generic.String.256" minOccurs="0" maxOccurs="1" />

An element with a null value (ex: <address2></address2>) now fails validation with The element is not 'nillable'.

@SanderMuller
Copy link

@freekmurze maybe we should revert this for now?

@radeno
Copy link
Contributor Author

radeno commented Nov 14, 2023

@freekmurze i created PR #226
but i am not sure if it works correctly, because I can't start tests. some PHP error not related to code. Can you try on your side please?

@radeno
Copy link
Contributor Author

radeno commented Nov 14, 2023

@SanderMuller i created fix PR, hope it will be merged soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants