cvc-elt.3.2.2: an element nilled by xsi:nil="true" may not have a fixed
{value constraint} (a nilled element has no value, so it cannot take a fixed
one). A nillable element MAY declare a fixed value, so the schema stays valid;
the conflict is an instance error only when such an element is actually nilled.
The check rides the shared nilErrors chokepoint, so the tree and streaming
validators enforce it identically; it prefers the matched particle's constraint
and falls back to the by-local-name map for particle-less paths (the unique-
named root). A nillable element that supplies its fixed value, a nilled element
with no fixed constraint, and a nilled element with a default (not fixed) value
are all unaffected. Catches addB065. XSTS invalid-instances-accepted 22 to 21,
valid-instances-rejected held at 0.
48 lines
1.9 KiB
Swift
48 lines
1.9 KiB
Swift
import Testing
|
|
@testable import PureXML
|
|
|
|
/// cvc-elt.3.2.2: a nilled element (xsi:nil="true" on a nillable declaration) may
|
|
/// not have a fixed {value constraint}. A nillable element MAY carry a fixed value
|
|
/// at the schema level (the declaration is valid); the conflict is an instance
|
|
/// error only when that element is actually nilled. Mirrors XSTS addB065.
|
|
@Suite("nilled element with a fixed value constraint")
|
|
struct SchemaNilFixedTests {
|
|
private func schema() throws -> PureXML.Schema.Document {
|
|
try PureXML.Schema.Document("""
|
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
<xs:element name="r">
|
|
<xs:complexType>
|
|
<xs:sequence>
|
|
<xs:element name="i" type="xs:string" minOccurs="0" maxOccurs="unbounded"
|
|
nillable="true" fixed="abc"/>
|
|
<xs:element name="j" type="xs:string" minOccurs="0" nillable="true"/>
|
|
</xs:sequence>
|
|
</xs:complexType>
|
|
</xs:element>
|
|
</xs:schema>
|
|
""")
|
|
}
|
|
|
|
private let xsi = #"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance""#
|
|
|
|
@Test("the schema (nillable element with a fixed value) compiles")
|
|
func test_schemaValid() throws {
|
|
_ = try schema() // does not throw
|
|
}
|
|
|
|
@Test("nilling a fixed-valued element is rejected")
|
|
func test_nilledFixedRejected() throws {
|
|
#expect(try !schema().validate(#"<r \#(xsi)><i xsi:nil="true"/></r>"#).isEmpty)
|
|
}
|
|
|
|
@Test("supplying the fixed value (not nilling) is accepted")
|
|
func test_fixedValueAccepted() throws {
|
|
#expect(try schema().validate(#"<r \#(xsi)><i>abc</i></r>"#).isEmpty)
|
|
}
|
|
|
|
@Test("nilling a nillable element with no fixed value stays valid")
|
|
func test_nilledNoFixedAccepted() throws {
|
|
#expect(try schema().validate(#"<r \#(xsi)><j xsi:nil="true"/></r>"#).isEmpty)
|
|
}
|
|
}
|