Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does XmlDocument.validate incorrectly validate an invalid xml document with empty namespaces?
    primarykey
    data
    text
    <p>I'm trying to validate a XML document I'm creating in the code before i save it. However my code always pass through the validation with no problem even when i input incorrect value on purpose. What is the problem with the code?</p> <pre><code>private XmlDocument xmlDocChanges = new XmlDocument(); public void Validate() { xmlDocChanges.Schemas.Add("http://www.w3.org/2001/XMLSchema", "xsd/Customization.xsd"); ValidationEventHandler eventHandler = new ValidationEventHandler(ValidationCallBack); xmlDocChanges.Validate(eventHandler); } public void ValidationCallBack (object sender, ValidationEventArgs args) { if(args.Severity == XmlSeverityType.Error || args.Severity == XmlSeverityType.Warning) { throw new Exception(args.Exception.Message); } } </code></pre> <p>EDIT Example XSD.</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; &lt;xs:complexType name="FirstNode"&gt; &lt;xs:annotation&gt; &lt;xs:documentation&gt;First node&lt;/xs:documentation&gt; &lt;/xs:annotation&gt; &lt;xs:attribute name="Identifier" type="xs:string" use="required" /&gt; &lt;xs:attribute name="Bool" type="xs:boolean" use="optional" /&gt; &lt;/xs:complexType&gt; &lt;/xs:schema&gt; </code></pre> <p>XML</p> <pre><code>&lt;Customizations FormatVersion="1" xsi:noNamespaceSchemaLocation="Customization.xsd"&gt; &lt;Customization&gt; &lt;Application name="App"&gt; &lt;FirstNode Identifier="one" Bool="NoValue"&gt;&lt;/FirstNode&gt; &lt;/Application&gt; &lt;/Customization&gt; &lt;/Customizations&gt; </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