-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Formalize how to express null value in xml #3959
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
Comments
@ahmednfwela Thanks for reporting this, and for the detailed research and references. Preliminary analysis for elementsXML 1.0, section 3.1 "Start-Tags, End-Tags, and Empty-Element Tags" states that the element forms The meaning of "empty" seems to depend on context/implementation; for string-valued elements "empty" means the empty string. So approach 3 ( Preliminary analysis for attributesXML 1.0, section 3.3.3 "Attribute-Value Normalization" describes an algorithm that MUST be applied before the value of an attribute is passed to the application or checked for validity. This algorithm begins with a normalized value consisting of the empty string, then appends to it. Thus attribute values are always strings, potentially the empty string, and never So approach 2 (disallow nullable attributes) seems to be the way forward. |
@ralfhandl For attributes, is there an Option 3: omit the attribute? |
I am asking because due to compatibility reasons, we cannot forbid |
@handrews How would this be distinguishable from |
@ahmednfwela in practice, it's probably not. But we can't do the preferred option of forbidding |
so we can say that for attributes setting |
@ahmednfwela we can't do anything that contradicts specified behavior in OAS 3.1. |
@handrews but this is already contradicting OAS 3.1, as a schema with |
Hmm... I do see your point, @ahmednfwela . I'm kind of at the point of throwing my hands up on this and saying that if you try to use |
Since XML has no concept of
null
, how can we handle validating a null value (both as an attribute and as an element) ?consider the following 3.0 schema :
notice how
required
here prevents us from removing the attribute/elementI have thought about this, and here are some of the approaches I came up with:
For elements
Approach 1: self closing tags
Pros: Makes sense to whoever reads it
Cons: Nothing i can think of, but maybe some xml parsers can consider a self-closing tag equivalent to empty string and don't distinguish between them, which means they don't survive round tripping:
e.g.
<name />
gets represented on the way back to:<name></name>
Approach 2: empty string
Cons: if the property is of type string, it's not possible to distinguish between a non-null empty string and a null.
Workaround: force strings to be wrapped around double quotes, e.g.
Ofc this workaround is very problematic and not good since most parsers consider
""
A valid 2 character string.Approach 3: special marker attribute
Pros: Can represent nulls consistently without having to check the contents of the element, this is also how xml schema does it.
Cons: Size overhead of having to use
xsi:nil="true"
everywhere null is used.For attributes
Approach 1: empty string
Approach 2: disallow nullable attributes altogether
make it that
xml.attribute: true
andnullable: true
are mutually exclusiveThe text was updated successfully, but these errors were encountered: