Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-41821

XMLISVALID returns unexepected result, various corner cases

    XMLWordPrintable

Details

    • Bug
    • Status: In Progress (View Workflow)
    • Major
    • Resolution: Unresolved
    • N/A
    • 13.2
    • XML Functions
    • None
    • Q3/2026 Server Maintenance, Q3/2026 Server Development, Q4/2026 Server Maintenance

    Description

      --echo # empty element of a non-string simple type is accepted, expect 0 for all three
      set @s='<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:simpleType name="e"><xs:restriction base="xs:string"><xs:enumeration value="x"/></xs:restriction></xs:simpleType>
      <xs:element name="r"><xs:complexType><xs:sequence>
      <xs:element name="i" type="xs:int"/><xs:element name="b" type="xs:boolean"/><xs:element name="e" type="e"/>
      </xs:sequence></xs:complexType></xs:element></xs:schema>';
      select XMLISVALID('<r><i/><b>true</b><e>x</e></r>', @s) as empty_int;
      select XMLISVALID('<r><i>1</i><b/><e>x</e></r>', @s) as empty_bool;
      select XMLISVALID('<r><i>1</i><b>true</b><e/></r>', @s) as empty_enum;
       
      --echo # complexType with only optional particles rejects an empty element, expect 1 for all but control
      select XMLISVALID('<r/>','<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="r"><xs:complexType><xs:sequence><xs:element name="c" type="xs:string" minOccurs="0"/></xs:sequence></xs:complexType></xs:element></xs:schema>') as seq_opt;
      select XMLISVALID('<r/>','<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="r"><xs:complexType><xs:all><xs:element name="a" type="xs:int" minOccurs="0"/></xs:all></xs:complexType></xs:element></xs:schema>') as all_opt;
      select XMLISVALID('<r/>','<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="r"><xs:complexType><xs:choice><xs:element name="a" type="xs:int" minOccurs="0"/></xs:choice></xs:complexType></xs:element></xs:schema>') as choice_opt;
      select XMLISVALID('<r/>','<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="r"><xs:complexType><xs:sequence><xs:sequence><xs:element name="a" type="xs:int" minOccurs="0"/></xs:sequence></xs:sequence></xs:complexType></xs:element></xs:schema>') as nested_opt;
      select XMLISVALID('<r/>','<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:group name="G"><xs:sequence><xs:element name="a" type="xs:int" minOccurs="0"/></xs:sequence></xs:group><xs:element name="r"><xs:complexType><xs:group ref="G"/></xs:complexType></xs:element></xs:schema>') as group_opt;
      select XMLISVALID('<r/>','<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="r"><xs:complexType><xs:sequence minOccurs="0"><xs:element name="a" type="xs:int"/></xs:sequence></xs:complexType></xs:element></xs:schema>') as control;
       
      --echo # choice maxOccurs>1 picking the same alternative twice, expect 1
      set @s='<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="root"><xs:complexType><xs:choice maxOccurs="2"><xs:element name="n" type="xs:int"/><xs:element name="m" type="xs:int"/></xs:choice></xs:complexType></xs:element></xs:schema>';
      select XMLISVALID('<root><n>1</n><m>2</m></root>', @s) as n_then_m;
      select XMLISVALID('<root><n>1</n><n>2</n></root>', @s) as n_then_n;
       
      --echo # minOccurs/maxOccurs on <xs:group ref> are ignored, expect 1 for both
      set @s='<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:group name="g"><xs:sequence><xs:element name="a" type="xs:int"/><xs:element name="b" type="xs:int"/></xs:sequence></xs:group>
      <xs:element name="r"><xs:complexType><xs:group ref="g" maxOccurs="2"/></xs:complexType></xs:element></xs:schema>';
      select XMLISVALID('<r><a>1</a><b>2</b><a>1</a><b>2</b></r>', @s) as max_occurs;
      set @s='<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:group name="g"><xs:sequence><xs:element name="a" type="xs:int"/></xs:sequence></xs:group>
      <xs:element name="r"><xs:complexType><xs:sequence><xs:group ref="g" minOccurs="0"/><xs:element name="b" type="xs:int"/></xs:sequence></xs:complexType></xs:element></xs:schema>';
      select XMLISVALID('<r><b>2</b></r>', @s) as min_occurs;
       
      --echo # parsed but not enforced, expect 0 in each case
      set @s='<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="r"><xs:complexType><xs:attribute name="a" type="xs:int" use="required"/><xs:attribute name="b" type="xs:string" fixed="z"/></xs:complexType></xs:element></xs:schema>';
      select XMLISVALID('<r/>', @s) as missing_required_attribute;
      select XMLISVALID('<r a="1" b="y"/>', @s) as fixed_attribute_differs;
      set @s='<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:simpleType name="li"><xs:list itemType="xs:int"/></xs:simpleType>
      <xs:simpleType name="un"><xs:union memberTypes="xs:int xs:boolean"/></xs:simpleType>
      <xs:element name="r"><xs:complexType><xs:sequence>
      <xs:element name="li" type="li"/><xs:element name="un" type="un"/><xs:element name="d" type="xs:date"/>
      </xs:sequence></xs:complexType></xs:element></xs:schema>';
      select XMLISVALID('<r><li>1 x</li><un>1</un><d>2024-01-01</d></r>', @s) as list_item;
      select XMLISVALID('<r><li>1</li><un>zz</un><d>2024-01-01</d></r>', @s) as union_member;
      select XMLISVALID('<r><li>1</li><un>1</un><d>2023-02-30</d></r>', @s) as bad_calendar_date;
      set @s='<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="r"><xs:complexType><xs:sequence><xs:any minOccurs="2" maxOccurs="2"/></xs:sequence></xs:complexType></xs:element></xs:schema>';
      select XMLISVALID('<r><a/></r>', @s) as any_too_few;
      select XMLISVALID('<r><a/><a/><a/></r>', @s) as any_too_many;
       
      --echo # element without type is xs:anyType per XSD, expect 1 for all three
      set @s='<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="a"/></xs:schema>';
      select XMLISVALID('<a>text</a>', @s) as a_text, XMLISVALID('<a><b/></a>', @s) as a_child, XMLISVALID('<a/>', @s) as a_empty;
      

      # empty element of a non-string simple type is accepted, expect 0 for all three
      set @s='<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:simpleType name="e"><xs:restriction base="xs:string"><xs:enumeration value="x"/></xs:restriction></xs:simpleType>
      <xs:element name="r"><xs:complexType><xs:sequence>
      <xs:element name="i" type="xs:int"/><xs:element name="b" type="xs:boolean"/><xs:element name="e" type="e"/>
      </xs:sequence></xs:complexType></xs:element></xs:schema>';
      select XMLISVALID('<r><i/><b>true</b><e>x</e></r>', @s) as empty_int;
      empty_int
      1
      select XMLISVALID('<r><i>1</i><b/><e>x</e></r>', @s) as empty_bool;
      empty_bool
      1
      select XMLISVALID('<r><i>1</i><b>true</b><e/></r>', @s) as empty_enum;
      empty_enum
      1
      # complexType with only optional particles rejects an empty element, expect 1 for all but control
      select XMLISVALID('<r/>','<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="r"><xs:complexType><xs:sequence><xs:element name="c" type="xs:string" minOccurs="0"/></xs:sequence></xs:complexType></xs:element></xs:schema>') as seq_opt;
      seq_opt
      0
      select XMLISVALID('<r/>','<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="r"><xs:complexType><xs:all><xs:element name="a" type="xs:int" minOccurs="0"/></xs:all></xs:complexType></xs:element></xs:schema>') as all_opt;
      all_opt
      0
      select XMLISVALID('<r/>','<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="r"><xs:complexType><xs:choice><xs:element name="a" type="xs:int" minOccurs="0"/></xs:choice></xs:complexType></xs:element></xs:schema>') as choice_opt;
      choice_opt
      0
      select XMLISVALID('<r/>','<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="r"><xs:complexType><xs:sequence><xs:sequence><xs:element name="a" type="xs:int" minOccurs="0"/></xs:sequence></xs:sequence></xs:complexType></xs:element></xs:schema>') as nested_opt;
      nested_opt
      0
      select XMLISVALID('<r/>','<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:group name="G"><xs:sequence><xs:element name="a" type="xs:int" minOccurs="0"/></xs:sequence></xs:group><xs:element name="r"><xs:complexType><xs:group ref="G"/></xs:complexType></xs:element></xs:schema>') as group_opt;
      group_opt
      0
      select XMLISVALID('<r/>','<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="r"><xs:complexType><xs:sequence minOccurs="0"><xs:element name="a" type="xs:int"/></xs:sequence></xs:complexType></xs:element></xs:schema>') as control;
      control
      1
      # choice maxOccurs>1 picking the same alternative twice, expect 1
      set @s='<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="root"><xs:complexType><xs:choice maxOccurs="2"><xs:element name="n" type="xs:int"/><xs:element name="m" type="xs:int"/></xs:choice></xs:complexType></xs:element></xs:schema>';
      select XMLISVALID('<root><n>1</n><m>2</m></root>', @s) as n_then_m;
      n_then_m
      1
      select XMLISVALID('<root><n>1</n><n>2</n></root>', @s) as n_then_n;
      n_then_n
      0
      # minOccurs/maxOccurs on <xs:group ref> are ignored, expect 1 for both
      set @s='<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:group name="g"><xs:sequence><xs:element name="a" type="xs:int"/><xs:element name="b" type="xs:int"/></xs:sequence></xs:group>
      <xs:element name="r"><xs:complexType><xs:group ref="g" maxOccurs="2"/></xs:complexType></xs:element></xs:schema>';
      select XMLISVALID('<r><a>1</a><b>2</b><a>1</a><b>2</b></r>', @s) as max_occurs;
      max_occurs
      0
      set @s='<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:group name="g"><xs:sequence><xs:element name="a" type="xs:int"/></xs:sequence></xs:group>
      <xs:element name="r"><xs:complexType><xs:sequence><xs:group ref="g" minOccurs="0"/><xs:element name="b" type="xs:int"/></xs:sequence></xs:complexType></xs:element></xs:schema>';
      select XMLISVALID('<r><b>2</b></r>', @s) as min_occurs;
      min_occurs
      0
      # parsed but not enforced, expect 0 in each case
      set @s='<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="r"><xs:complexType><xs:attribute name="a" type="xs:int" use="required"/><xs:attribute name="b" type="xs:string" fixed="z"/></xs:complexType></xs:element></xs:schema>';
      select XMLISVALID('<r/>', @s) as missing_required_attribute;
      missing_required_attribute
      1
      select XMLISVALID('<r a="1" b="y"/>', @s) as fixed_attribute_differs;
      fixed_attribute_differs
      1
      set @s='<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:simpleType name="li"><xs:list itemType="xs:int"/></xs:simpleType>
      <xs:simpleType name="un"><xs:union memberTypes="xs:int xs:boolean"/></xs:simpleType>
      <xs:element name="r"><xs:complexType><xs:sequence>
      <xs:element name="li" type="li"/><xs:element name="un" type="un"/><xs:element name="d" type="xs:date"/>
      </xs:sequence></xs:complexType></xs:element></xs:schema>';
      select XMLISVALID('<r><li>1 x</li><un>1</un><d>2024-01-01</d></r>', @s) as list_item;
      list_item
      1
      select XMLISVALID('<r><li>1</li><un>zz</un><d>2024-01-01</d></r>', @s) as union_member;
      union_member
      1
      select XMLISVALID('<r><li>1</li><un>1</un><d>2023-02-30</d></r>', @s) as bad_calendar_date;
      bad_calendar_date
      1
      set @s='<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="r"><xs:complexType><xs:sequence><xs:any minOccurs="2" maxOccurs="2"/></xs:sequence></xs:complexType></xs:element></xs:schema>';
      select XMLISVALID('<r><a/></r>', @s) as any_too_few;
      any_too_few
      1
      select XMLISVALID('<r><a/><a/><a/></r>', @s) as any_too_many;
      any_too_many
      1
      # element without type is xs:anyType per XSD, expect 1 for all three
      set @s='<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="a"/></xs:schema>';
      select XMLISVALID('<a>text</a>', @s) as a_text, XMLISVALID('<a><b/></a>', @s) as a_child, XMLISVALID('<a/>', @s) as a_empty;
      a_text	a_child	a_empty
      0	0	1
      

      Attachments

        Issue Links

          Activity

            People

              holyfoot Alexey Botchkov
              alice Alice Sherepa
              Alexander Barkov Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 1d 19m
                  1d 19m
                  Remaining:
                  Remaining Estimate - 1d 19m
                  1d 19m
                  Logged:
                  Time Spent - Not Specified
                  Not Specified

                  Git Integration

                    Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.