Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

Bug in Xdocument.Validate

$
0
0

I am trying to validate and XML Document against my XSD, which specifies a Boolean attribute with a fixed value.  The validation fails to catch if the attribute value does not match the fixed value.

The following code should fail validation since required="false" does not match the fixed value of true, but it passes.  If I have a fixed value for a string attribute that does have to match to pass, but the Boolean value doesn't get caught by the validation.

Sample Code

  _transactionXSD = new XmlSchemaSet();
        _transactionXSD.Add(null, "testValidation.xsd");
        XDocument validateDoc = XDocument.Load("TestDocument.xml");

        _transactionXSD.CompilationSettings.EnableUpaCheck = true;
        bool errors = false;

        validateDoc.Validate(_transactionXSD, (o, ea) => { errors = true; }, true);
        if (errors)
        {
            MessageBox.Show("Failed Validation");
        }
        else
        {
            MessageBox.Show("PassedValidation");
        }

Sample XML

<?xml version="1.0" encoding="UTF-8"?><MyElement required="false" id="this.field" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:///C:/testValidation.xsd">SomeData</MyElement>

Sample XSD

<?xml version="1.0" encoding="UTF-8"?><!-- W3C Schema generated by XMLSpy v2015 rel. 3 (http://www.altova.com) --><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="MyElement"><xs:complexType><xs:simpleContent><xs:extension base="ST_MyElement"><xs:attribute ref="required" fixed="true" use="required"/><xs:attribute name="id" use="required"><xs:simpleType><xs:restriction base="xs:string"><xs:enumeration value="this.field"/></xs:restriction></xs:simpleType></xs:attribute></xs:extension></xs:simpleContent></xs:complexType></xs:element><xs:simpleType name="ST_MyElement"><xs:restriction base="xs:string"/></xs:simpleType><xs:attribute name="required" default="true"><xs:simpleType><xs:restriction base="xs:boolean"/></xs:simpleType></xs:attribute></xs:schema>


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>