Xml 如果元素没有内容,则需要特定的属性值
假设我有这样一个类型定义:Xml 如果元素没有内容,则需要特定的属性值,xml,xsd,Xml,Xsd,假设我有这样一个类型定义: <xs:complexType name="title-type"> <xs:simpleContent> <xs:extension base="xs:string">
<xs:complexType name="title-type">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="hide" type="xs:boolean" default="false" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
这允许空内容,这很好。但是,我想要求,如果内容为空,则属性hide=“true”
我该怎么做?您不能在XSD 1.0中表达您的约束,但可以在XSD 1.1中使用
xs:assert
XSD 1.1
您可以使用XSD 1.1吗?也许您需要的是xs:nillable属性?
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
vc:minVersion="1.1">
<xs:complexType name="title-type">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="hide" type="xs:boolean" default="false" />
<xs:assert test=". != '' or @hide = true()"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:element name="title" type="title-type"/>
</xs:schema>