开发者

Nillable usage on heirachical XML?

When you have an XML structure like below:

<xs:complexType name="ContactSuperType">
    <xs:sequence>
        <xs:element name="Details">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="GivenName" type="xs:string" nillable="true"/>
                    <xs:element name="Initials" type="xs:string" nillable="true" minOccurs="0"/>
                    <xs:element name="FamilyName" type="xs:string" nillable="true"/>
                </xs:sequence>
            </xs:complexType>
 开发者_C百科       </xs:element>
        <xs:element ref="Address" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>

Should <xs:element name="Details"> be <xs:element name="Details" nillable="true"> as well?


It's up to you. There's no rule in the language that says if all the children of an element are nillable, then the parent should be nillable too. But it may be a design practice you choose to follow. It depends why you're using xsi:nil in the first place. Personally, I have never seen a situation where I found it remotely useful - allowing an element to be empty and allowing it to be absent already gives two ways of handling missing data, and I see no need for a third.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜