我想要电话元素的独特价值 [英] I want unique value for telephone element

查看:58
本文介绍了我想要电话元素的独特价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 xml 和架构.我想要一个架构,其中电话元素值必须是唯一的.我尝试使用 unique 但无法理解它是如何工作的.抱歉这个愚蠢的问题,但我正在学习.

I am learning xml and schema.I want a schema where Telephone element value have to be unique. I try with unique but can't understand how it's work. Sorry for this silly question but i am learning.

xml

<?xml version="1.0" encoding="utf-8" ?>
<Company xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
   <Employee>
     <Name>ABC</Name>
     <Telephone>9998887770</Telephone>
   </Employee>
   <Employee>
      <Name>DEF</Name>
      <Telephone>9998887770</Telephone>
   </Employee>  
   <Employee> 
       <Name>GHI</Name>
       <Telephone>1234567890</Telephone>
   </Employee>
</Company>

架构

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="EmployeeSchema"
       elementFormDefault="qualified"
       attributeFormDefault="unqualified"
       xmlns:xs="http://www.w3.org/2001/XMLSchema">

     <xs:element name="Name"/>
     <xs:element name="Telephone" />

     <xs:simpleType name="string32">
         <xs:restriction base="xs:token">
         <xs:maxLength value="32"/>
     </xs:restriction>

     <xs:element name="Company">
        <xs:complexType>
           <xs:sequence>
              <xs:element ref="Employee" maxOccurs="unbounded"/>
           </xs:sequence>
        </xs:complexType>
    <!--Here i try to implement unique--->
        <xs:unique name="Company">
            <xs:selector xpath="Telephone"/>
            <xs:field xpath="Telephone"/>
        </xs:unique> 
     </xs:element>

       <xs:element name="Employee">
          <xs:complexType>
            <xs:sequence>      
                <xs:element ref="Name"/>
                <xs:element ref="Telephone"/>     
            </xs:sequence>
         </xs:complexType>
      </xs:element>
</xs:schema>

推荐答案

尝试

<xs:unique name="Company-Employee-Phone">
    <xs:selector xpath="Employee"/>
    <xs:field xpath="Telephone"/>
</xs:unique>

规则是这样的:如果您希望 X 中的每个 Y 都具有不同的 Z 值,则在 X 的定义中定义 xs:unique 约束,使用选择 Y 的路径从 X 作为 xs:selector,以及从 Y 中选择 Z 作为 xs:field 的路径.

The rule is this: if you want every Y within an X to have a distinct value for Z, then define the xs:unique constraint in the definition of X, use a path that selects Y from X as the xs:selector, and a path that selects Z from Y as the xs:field.

这篇关于我想要电话元素的独特价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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