Skip to content

v3.1.2: Provide guidance on null in XML. #4612

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

Merged
merged 2 commits into from
May 22, 2025
Merged

Conversation

handrews
Copy link
Member

@handrews handrews commented May 18, 2025

Fixes:

There really isn't a native null type in XML, as both elements and attributes that are empty have an empty string value.

We also need to leave the behavior implementation-defined for compatibility.

However, attaching the xsi:nil=true attribute to an empty element is the closest thing to a null element.

Attributes are harder, and the best I can come up with is letting null behave the same as an omitted attribute for the purpose of serialization. This means that for round-tripping, whether a missing attribute is parsed into a null property or as an omitted property depends on whether the schema allows null.

This attribute behavior is a bit weird, but I can't come up with anything else that has a hope of round-tripping propery, and we can't outright forbid null in a patch release. If PR #4592 is accepted, we could forbid type: [..., "null"] or type: "null" with xml: {nodeType: "attribute"} and leave the behavior with the deprecated xml: {attribute: true} unchanged.

So I guess the question here is whether the attribute guidance is more confusing than helpful. The fact that we got asked about it suggests that we ought to say something, though.

  • schema changes are included in this pull request
  • schema changes are needed for this pull request but not done yet
  • no schema changes are needed for this pull request

There really isn't a native `null` type in XML, as both elements
and attributes that are empty have an empty string value.

We also need to leave the behavior implementation-defined
for compatibility.

However, the `xsi:nil` attribute is the closest thing to a `null`
element.  Attributes are harder, and the best I can come up with
is letting `null` behave the same as an omitted attribute for the
purpose of serialization.
@handrews handrews requested review from a team as code owners May 18, 2025 04:20
@handrews handrews added xml clarification requests to clarify, but not change, part of the spec media and encoding Issues regarding media type support and how to encode data (outside of query/path params) labels May 18, 2025
@handrews handrews added this to the v3.1.2 milestone May 18, 2025
@handrews handrews linked an issue May 18, 2025 that may be closed by this pull request
miqui
miqui previously approved these changes May 18, 2025
Copy link
Contributor

@miqui miqui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@handrews > we could forbid type: [..., "null"] or type: "null" with xml: {nodeType: "attribute"} and leave the behavior with the deprecated xml: {attribute: true} unchanged.

This seems like reasonable constraint.

Copy link
Contributor

@ralfhandl ralfhandl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, just a doubt on punctuation

Copy link
Contributor

@lornajane lornajane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a good addition

@lornajane lornajane merged commit b3dd05f into OAI:v3.1-dev May 22, 2025
2 checks passed
@lornajane
Copy link
Contributor

@handrews Will you create the same change for 3.2? Can we link the PRs together when you do?

@handrews
Copy link
Member Author

@lornajane removing JSON examples was just 3.2, although I would not object to removing them in 3.1.2 if folks want.

I was thinking of adding this to PR #4592 as otherwise it will be a mess of git conflicts. Alternatively, we could wait for #4592 to merge and then I'll port this (and other XML-related 3.1.2 changes). I was going to do one big 3.1.2->3.2 sync PR with individual commits (like I did last time around for the final sync PRs), but I can do this one separately if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clarification requests to clarify, but not change, part of the spec media and encoding Issues regarding media type support and how to encode data (outside of query/path params) xml
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formalize how to express null value in xml
4 participants