是否可以在XML Schema中为缺少的元素定义默认值.我有以下代码段:
<xs:element name="protocol" nillable="false" minOccurs="0" default="ftp">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="ftp"/>
<xs:enumeration value="webdav"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
如果我有XML文件
<protocol>ftp</protocol>
Run Code Online (Sandbox Code Playgroud)
要么
<protocol>webdav</protocol>
Run Code Online (Sandbox Code Playgroud)
它验证并获得正确的价值.如果我有XML文件
<protocol></protocol>
Run Code Online (Sandbox Code Playgroud)
它也验证并获得默认值ftp.
我的搜索显示默认属性值在缺少属性时应用,默认元素值在元素为空时应用.是否可以为缺少的元素设置默认值?
问候
rambius