Tell me, is it possible in XSD Scheme 1.0:

  1. Control the presence of one or another attribute in the element, and must be either one or the other (simultaneous presence is excluded)

    • <el value_1="11" value_2="22" /> - Error, both elements are present.
    • <el value_1="11" /> - Check passes
    • <el value_2="22" /> - Check passes
  2. Control the presence of an attribute or, if not, the presence of a child element

    • <el value="11"/> - check passes
    • <el><value>11</value></el> - the check passes
    • <el value="11"><value>11</value> - Error, both attribute and nested element are present
  3. Control the presence of an attribute or element content.

    • <el value="11" /> - check passes
    • <el>11</el> - check passes
    • <el value="11">11</el> - error, both attribute and nested data are present

I read that in XSD Schema 1.1 such can be controlled by creating my own control rules with xs: assert, but alas, the scheme is used for version 1.0

    1 answer 1

    1. Not. This is only possible for items
    2. Not. All that is possible is to declare the element and / or attribute mandatory or not.
    3. Not.

    If you have such tricky rules, you can validate with XSL

    <el value_1="11" value_2="22" /> - Error, both elements are present.

     <xsl:template match="el"> <xsl:if test="@value_1 and @value_2> <xsl:message terminate="yes"> Опаньки! </xsl:message> </xsl:template> 

    Well, or first convert the input document to something validated, and then set the XSD on. And process the already converted document.

    • I understand correctly that they are mutually exclusive? Those. either validate through xsd or xsl. Never last used. Through XMLDocument (C #) can this validation scheme be used? Does VS 2013 support this standard? - pincher1519
    • @ pincher1519 No. Not mutually exclusive. Even on the contrary, I would recommend first using XSD to weed out major problems, and then tuning through XSL. Through XMLDocument is possible. Just call the transformation. VS2013 is a compiler. He doesn't care what you use in the program - Anton Shchyrov
    • @Anton_Shchyrov, I noticed that the xsd scheme itself can control the presence of attributes and elements based on itself. But I do not understand how she does it. For example, xs: element may have a type attribute if there is no xs: complextype or xs: simpletype inside the element. If these elements are element, then the attribute type cannot be specified. How do they implement this check at the Scheme level? - pincher1519
    • @ pincher1519 Checked. The element easily lives with the type attribute and the nested complexType. At least during the validation of such a scheme, the XMLSchema.xsd scheme did not cause any errors - Anton Shchyrov
    • @Anton_Shchyrov really. And the studio throws a mistake. So somehow additionally checks the scheme. - pincher1519