XML : XmlDocument.Validate not supported attributes or elements

How can I get ValidationEvents if theire are attributes or elements in the xml that are not defined in the xsd.

xsd:

      <?xml version="1.0" encoding="utf-8"?>      <xsd:schema id="VoiceXmlTSPro"                  targetNamespace="http://tempuri.org/VoiceXmlTSPro.xsd"                  elementFormDefault="qualified"                  xmlns="http://tempuri.org/VoiceXmlTSPro.xsd"                  xmlns:xsd="http://www.w3.org/2001/XMLSchema">      <!-- Elements-->      <xsd:element name="vxml">       <xsd:complexType>        <xsd:attribute ref="base"/>        <xsd:attribute ref="lang"/>        </xsd:complexType>       </xsd:element>          <!-- End Elements-->         <!-- Attributes-->         <xsd:attribute name="base" type="xsd:anyURI">       </xsd:attribute>       <xsd:attribute name="lang" type="xsd:string">        </xsd:attribute>      <!-- End Attributes-->    </xsd:schema>    

xml:

      <?xml version="1.0" encoding="utf-8" ?>       <vxml application="notsupported" lang="en-US"     base="http://www.zebra.com">         <unknow></unknow>        </vxml>    

I want a warning for the application attribute and for the unknow ellement. But this code is not trowing any event.

      public override void Validate(string source)      {          ValidationResults.Clear();          XmlSchemaFactory xmlSchemaFactory = new XmlSchemaFactory();          XmlReaderSettings vxmlTestSettings = new XmlReaderSettings();          vxmlTestSettings.ValidationType = ValidationType.Schema;          vxmlTestSettings.ValidationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints| XmlSchemaValidationFlags.ReportValidationWarnings ;          try          {              XmlSchema xsdSchema = xmlSchemaFactory.Create(Resource.VoiceXmlTSPro);              if (xmlSchemaFactory.HasErrors())              {                  // if the schema is invalid the read wil not read                  return;              }              vxmlTestSettings.Schemas.Add(xsdSchema);              ValidationEventHandler eventHandler = new ValidationEventHandler(ValidationHandler);                using (MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes(source)))              using (XmlReader xmlReader = XmlReader.Create(stream, vxmlTestSettings))              {                  XmlDocument document = new XmlDocument();                  document.Load(xmlReader);                  document.Validate(eventHandler);              }          }          catch (Exception ex)          {              ...          }      }    

No comments:

Post a Comment