Note that there are some explanatory texts on larger screens.

plurals
  1. POXDocument.Validate is always successful
    primarykey
    data
    text
    <p>I have a schema file which does not define any target namespaces, i.e. its definition looks like this:</p> <pre><code>&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"&gt; &lt;!--Elements, attributes, etc. --&gt; &lt;/xs:schema&gt; </code></pre> <p>The corresponding XML looks like this:</p> <pre><code>&lt;Documents p1:CRC="0" p1:Date="1900-01-01T01:01:01+01:00" p1:Name="Test" p1:Status="new" xmlns:p1="http://www.tempuri.org/pdms.xsd" xmlns="http://www.tempuri.org/pdms.xsd"&gt; &lt;p1:Document p1:Date="2010-12-23T07:59:45" p1:ErrorCode="0" p1:ErrorMessage="" p1:Number="TEST00001" p1:Status="new"/&gt; &lt;/Documents&gt; </code></pre> <p>Validation of this XML against the schema with e.g. Altova XMLSpy or Oxygen XML Editor fails.</p> <p>However my validation in C# (.NET 4.0) does not fail. The XML is processed as an <code>XDocument</code> object. If I have understood correctly then <code>XDocument.Validate()</code> does a lax validation if no namespace is found in the schema. Thus the validation does not fail. But then how can I implement a "strict" validation for <code>XDocument</code>?</p> <p>This is how I try to validate the XML:</p> <pre><code>public static void ValidateXml(XDocument xml, string xsdFilename) { XmlReaderSettings settings = new XmlReaderSettings(); XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.Add(string.empty, xsdFilename); settings.ValidationType = ValidationType.Schema; settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings; settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallback); xml.Validate(schemaSet, ValidationCallback); } private static void ValidationCallback(object sender, ValidationEventArgs args) { if (args.Severity == XmlSeverityType.Warning) { // Do warning stuff... } else if (args.Severity == XmlSeverityType.Error) { // Do error stuff... } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload