如何在xsd中使属性唯一?

时间:2014-12-26 12:34:02

标签: xml xml-parsing xsd xsd-validation

XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<p:configuration 
  xsi:schemaLocation = 
    "http://text.ru/sv/ATMScenario/ScreenConfiguration
     ATMScreenConfiguration.xsd " 
  xmlns:p="http://text.ru/sv/ATMScenario/ScreenConfiguration" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <p:screen screenNumber="001" 
    screenName="Do you need more time" />
  <p:screen screenNumber="002" 
    screenName="Do you need more time" />
  <p:screen screenNumber="004" 
    screenName="Currency prefix for amount entry" />
  <p:screen screenNumber="004" 
    screenName="Thousands separator for amount entry" />
</p:configuration>

XSD:

...
<xsd:element name="configuration" 
  type="configuration.configuration.type">
  <xsd:unique name="uConfiguration">
    <xsd:selector xpath="screen" /> 
    <xsd:field xpath="@screenNumber" /> 
  </xsd:unique>
</xsd:element>

我想要属性&#39; screenNumber&#39;屏幕&#39;标签是唯一的。我在哪里弄错了?

1 个答案:

答案 0 :(得分:0)

可能是由于名称空间,请尝试为选择器添加前缀:

    <xsd:unique name="uConfiguration">
        <xsd:selector xpath="p:screen"/>
        <xsd:field xpath="@screenNumber"/>
    </xsd:unique>