XML模式以限制一个字段基于另一个字段 [英] XML Schema to restrict one field based on another

查看:108
本文介绍了XML模式以限制一个字段基于另一个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下架构,用于确保一个人的PhoneNumberPhoneNumberType(家庭,工作等)不超过10个字符.但是,我想改进此架构,以便在未提供PhoneNumber的情况下不需要PhoneNumberType,而在提供PhoneNumber的情况下则需要PhoneNumberType.在XML Schema 1.0中有没有办法做到这一点?

I have the following schema, which I use to ensure that a person's PhoneNumber and PhoneNumberType (Home, Work, etc.) is not longer than 10 characters. However, I want to improve this schema so that PhoneNumberType is not required if a PhoneNumber is not provided, but is required if the PhoneNumber is provided. Is there a way to do this in XML Schema 1.0?

我知道可以使用<xs:assert/>在XML Schema 1.1中完成此操作,但是不幸的是,我仍然坚持使用XML Schema 1.0.

I am aware this could be accomplished in XML Schema 1.1 using <xs:assert/>, but unfortunately I am stuck with XML Schema 1.0.

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xs:element name="PhoneNumber">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:minLength value="0"/>
        <xs:maxLength value="10"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
  <xs:element name="PhoneNumberType">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:minLength value="0"/>
        <xs:maxLength value="10"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xsd:schema>

推荐答案

对不起,XML模式无法做到这一点.

Sorry, XML Schema can't do that.

一些类似的问题:

  • can the length of two xml lists be defined as being required to be equal?
  • Restrict Element Values Based on Attribute
  • How to use attribute value as a discriminator for XML polymorphic type selection?
  • How to Validate in XSD the xml node value against it’s neighbor xml node value

这篇关于XML模式以限制一个字段基于另一个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆