本文介紹了允許 XSD 日期元素為空字符串的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我想允許一個元素是 xs:date
或空字符串.
I would like to allow an element to be a xs:date
or an empty string.
這是我嘗試過的 XML 架構:
Here's an XML Schema that I've tried:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:lp="urn:oio:ebst:diadem:lokalplan:1"
targetNamespace="urn:oio:ebst:diadem:lokalplan:1"
elementFormDefault="qualified" xml:lang="DA"
xmlns:m="urn:oio:ebst:diadem:metadata:1">
<xs:import schemaLocation="../key.xsd" namespace="urn:oio:ebst:diadem:metadata:1" />
<xs:element name="DatoVedtaget" type="lp:DatoVedtagetType" />
<xs:complexType name="DatoVedtagetType">
<xs:simpleContent>
<xs:extension base="xs:date">
<xs:attribute ref="m:key" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="DatoVedtagetTypeString">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute ref="m:key" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>
如果元素包含一個值,我希望元素為 DatoVedtagetType
,如果它為空,我希望它為 DatoVedtagetTypeString
.我如何在這個架構中實現這樣的條件功能?
I want the element to be DatoVedtagetType
in a case it includes a value, and I want it to be DatoVedtagetTypeString
if it is empty. How I implement such a conditional functionality this schema?
推薦答案
根據問題的評論,目標是讓 DatoVedtaget
為 xs:date
或為空.這是表達這種約束的一種方式:
Per comments on the question, the goal is to have DatoVedtaget
be a xs:date
or empty. Here is a way to express such a constraint:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:lp="urn:oio:ebst:diadem:lokalplan:1"
xmlns:m="urn:oio:ebst:diadem:metadata:1"
targetNamespace="urn:oio:ebst:diadem:lokalplan:1"
elementFormDefault="qualified"
xml:lang="DA">
<xs:import schemaLocation="../key.xsd" namespace="urn:oio:ebst:diadem:metadata:1" />
<xs:element name="DatoVedtaget" type="lp:DatoVedtagetType" />
<xs:simpleType name="empty">
<xs:restriction base="xs:string">
<xs:enumeration value=""/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="dateOrEmpty">
<xs:union memberTypes="xs:date lp:empty"/>
</xs:simpleType>
<xs:complexType name="DatoVedtagetType">
<xs:simpleContent>
<xs:extension base="lp:dateOrEmpty">
<xs:attribute ref="m:key" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>
這篇關于允許 XSD 日期元素為空字符串的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!