Hello dear! Please help to make a scheme for xml-code:

<Подраздел имя="винты"> <Свойство тип="Число" имя="Диаметр" обозначение="d" единица="мм" /> <Свойство тип="Число" имя="Шаг" обозначение="p" единица="мм" /> <Свойство тип="Текст.Варианты" имя="Направление резьбы"> <Вариант>Правая</Вариант> <Вариант>Левая</Вариант> </Свойство> <Свойство тип="Да/Нет" имя="Полый?"/>Да</Свойство> </Подраздел> 

so that:

  1. for the property with type = "Number", the presence of child elements was excluded, and the attributes designation = "", units = "" were required.
  2. for the property type = "Text. Options" a minimum of 2 child <option> 'a was required, and the presence of attributes notation = "", units = "" was prohibited.
  3. for the property type = "Yes / No" is similar to paragraph 2 + the closing tag is mandatory, the content is limited to two options "yes" and "no".

In general terms, it is required to create a scheme in which the "Property" element changes attributes and child elements depending on the value type = "". And is it possible?

  • If I am not mistaken, it is impossible directly. - Alexander Petrov

1 answer 1

It's impossible. XSD does not support validation by value. Only by structure. Replace your XML with

 <Подраздел имя="винты"> <Число имя="Диаметр" обозначение="d" единица="мм" /> <Число имя="Шаг" обозначение="p" единица="мм" /> <Текст.Варианты имя="Направление резьбы"> <Вариант>Правая</Вариант> <Вариант>Левая</Вариант> </Текст.Варианты> <Логический имя="Полый?">Да</Логический> </Подраздел> 

And the task will have a solution

  • Apparently it will have to do. Thank you for your help! - xBobr 2:21 pm