Note that there are some explanatory texts on larger screens.

plurals
  1. PORelate PSVI GetSchemaInfo to the XSD Validation Error ValidationEventArgs.Message
    primarykey
    data
    text
    <p>I have a question about Microsoft's MSDN documentation for the <a href="http://msdn.microsoft.com/en-us/library/bb342577.aspx" rel="nofollow">Extenstions.GetSchemaInfo Method (XElement)</a> for .Net framework 4.0.</p> <p>I want to know if there's a way from within the </p> <pre><code>Private Sub DumpInvalidNodes(ByVal el As XElement) If el.GetSchemaInfo.Validity &lt;&gt; XmlSchemaValidity.Valid Then ... End If End Sub </code></pre> <p>Code to get the ValidationEventArgs.Message for the invalid node. This example works fine when you have numbered XML nodes like in the example: GrandChild1, GrandChild2. You can tell which invalid node is producing the validation errors by site. But when you have XML without numbered nodes, e.g.</p> <pre><code>&lt;Root&gt; &lt;Child&gt; &lt;GrandChild&gt;AAA&lt;/GrandChild&gt; &lt;GrandChild&gt;ZZZ&lt;/GrandChild&gt; &lt;GrandChild&gt;ZZZ&lt;/GrandChild&gt; &lt;/Child&gt; &lt;/Root&gt; </code></pre> <p>you get output that looks like this:</p> <pre><code>(1)Validating doc1 ... (2)The 'GrandChild' element is invalid - The value 'ZZZ' is invalid according to its datatype 'GCType' - The Enumeration constraint failed. (3)The 'GrandChild' element is invalid - The value 'ZZZ' is invalid according to its datatype 'GCType' - The Enumeration constraint failed. (4)doc1 did not validate (5)Invalid Element /Root (6)Invalid Element /Root/Child (7)Invalid Element /Root/Child/GrandChild (8)Invalid Element /Root/Child/GrandChild </code></pre> <p>I wanted a way to tell that line (7) referred to the ErrorMessage in line (2). </p> <p>I have an XML document that I'm running XSD validation against as this article shows and I wanted to parse the ValidationEventArgs.Message into a more user friendly message for complex data types. I'd like to do this in the DumpInvalidNodes() method because I have access to the invalid Node and can obtain other information from the node (like an ID) that the user can use to find and fix the validation problem.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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