XSD keyref с постоянным значением поля - PullRequest
0 голосов
/ 26 сентября 2018

Следующий XML-документ содержит несколько элементов a, каждый из которых имеет тип и идентификатор.Сочетание элементов type и id уникально.Он также содержит элемент a1_list, который должен содержать последовательность идентификаторов, ссылающихся на a элементы типа 1.

<root>
  <a><type>1</type><id>10</id></a>
  <a><type>2</type><id>10</id></a>
  <a><type>2</type><id>11</id></a>
  <a1_list><id>10</id><id>11</id></a1_list>
</root>

Следующая схема XML определяет это:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="root">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="a" maxOccurs="unbounded">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="type" type="xs:int"/>
              <xs:element name="id" type="xs:int"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="a1_list">
          <xs:complexType>
            <xs:sequence maxOccurs="unbounded">
              <xs:element name="id" type="xs:int"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
    <xs:key name="a_key">
      <xs:selector xpath="a"/>
      <xs:field xpath="type"/>
      <xs:field xpath="id"/>
    </xs:key>
  </xs:element>
</xs:schema>

Теперь, есть ли способ добавить ссылку на ключ, усиливающую ограничение на то, что элемент id в a1_list указывает на действительный идентификатор элемента a типа 1?Я попытался:

<xs:keyref name="a_ref" refer="a_key">
  <xs:selector xpath="a1_list/id"/>
  <xs:field xpath="."/>
  <xs:field xpath="1"/>
</xs:keyref>

Но это неверная ссылка на ключ в соответствии с xmllint:

> xmllint --noout --schema test.xsd test.xml
test.xsd:31: element field: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}field', attribute 'xpath': The XPath expression '1' could not be compiled.
WXS schema test.xsd failed to compile

Обновление: Я также пытался создать ключ только для a[type='1'], но это нетоже не работает.

<xs:key name="a1_key">
  <xs:selector xpath="a[type='1']"/>
  <xs:field xpath="id"/>
</xs:key>

дает

> xmllint --noout --schema ~/test.xsd ~/test.xml
test.xsd:29: element selector: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}selector', attribute 'xpath': The XPath expression 'a[type='1']' could not be compiled.
WXS schema test.xsd failed to compile

Я также взглянул на https://www.w3.org/TR/xmlschema-1/#c-selector-xpath. Если я правильно понимаю, мне действительно не повезлоВот.Кто-нибудь может подтвердить?

...