多个电子邮件收件人的 XML 架构 [英] XML Schema for multiple email recipients

查看:74
本文介绍了多个电子邮件收件人的 XML 架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个示例 XSD 来支持新元素中的多个电子邮件收件人.我需要不同元素中的每个收件人电子邮件地址.谁能帮我解释一下?

I need a sample XSD to support multiple email recipients in a new element. I require each recipient email address in a different element. Can anyone help me with explanation?

示例:

<EmailReceipts> 
    <address1></address1>
    <address2></address2>
</EmailReceipts>

推荐答案

首先,我建议不要在 address 元素中嵌入索引号:

First off, I'd recommend not embedding an index number in the address elements:

<EmailReceipts> 
  <address>john@example.com</address>
  <address>mary@example.org</address>
</EmailReceipts>

然后此 XSD 将验证上述 XML(以及其他具有附加 address 元素的 XML 文档):

Then this XSD will validate the above XML (as well as other XML documents with additional address elements):

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="EmailReceipts">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="address" maxOccurs="unbounded" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

上述 XSD 将允许 address 元素的任何字符串内容.如果你想更严格,你可以使用正则表达式来限制 address 的值:

The above XSD will allow any string contents for the address elements. If you've like to be more strict, you could use a regular expression to limit the values for address:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="EmailReceipts">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="address" maxOccurs="unbounded" type="EmailAddressType"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:simpleType name="EmailAddressType">
    <xs:restriction base="xs:string">
      <xs:pattern value="([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>

注意上面的正则表达式是一个许多 可能,每一种都具有不同程度的通用性和特异性 比你想象的更复杂的语法.

Note that the above regular expression is one of many possible, each having various degrees of generality and specificity over a syntax that is more involved than you might imagine.

这篇关于多个电子邮件收件人的 XML 架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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