Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9185665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:19:56+00:00 2026-06-17T19:19:56+00:00

I have an XDocument that I validate against an XML schema. When the XDocument

  • 0

I have an XDocument that I validate against an XML schema. When the XDocument is invalid I need to find the invalid XML nodes so that the user can easily navigate to the respective place in my application (e.g. by double-clicking a message on a message grid).

I use the System.Xml.Schema.Validate() extension method for that purpose. The second argument of the Validate() method is a System.Xml.ValidationEventHandler which is called on every invalid XML element. It passes a System.Xml.ValidationEventArgs. The ValidationEventArgs.Exception can be casted to System.Xml.Schema.XmlSchemaValidationException. Now the
XmlSchemaValidationException has a property SourceObject which I expected to hold a reference to the invalid XML node. Unfortunately it is always null.

The following snippet illustrates my usage:

XDocument doc = XDocument.Load(@"c:\temp\booksSchema.xml");

// Create the XmlSchemaSet class.
XmlSchemaSet sc = new XmlSchemaSet();

// Add the schema to the collection.
sc.Add("urn:bookstore-schema", @"c:\temp\books.xsd");

// Validate against schema
doc.Validate(sc, delegate(object sender, ValidationEventArgs e)
                {
                    XmlSchemaValidationException ve = e.Exception as XmlSchemaValidationException;
                    if (ve != null)
                    {
                        object errorNode = ve.SourceObject;    
                        // ve.SourceObject is always null
                    }
                });

The validation itself works correctly, but I cannot get a reference on the invalid node. Strangely, the same approach works well for System.Xml.XmlDocument, but unfortunately I must work with XDocument in this context.

Does anyone have a suggestion how the invalid node can be found in XDocument?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:19:58+00:00Added an answer on June 17, 2026 at 7:19 pm

    OK, I have the answer. The invalid node is the event handler’s “sender” itself. It can be cast to XContainer, XElement, …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XmlDocument in C# that I need to validate against an Xml
I'm trying to validate an XDocument with a compiled schema that I have (which
How can I get Eclipse Indigo to validate xml against xsd's that exist in
I have a loaded XDocument that I need to grab all the attributes that
I have found several sources regarding how to validate an xml document against a
I have an XML file (a sitemap using Google's <image:image> extensions) that I need
I have an XDocument file that I have loaded. (confirmed the working). I need
I have a XDocument that looks like this: XDocument outputDocument = new XDocument( new
I have an XDocument that looks similar to <root> <a> <b foo=1 bar=2 />
I have a document that my asp.net page is creating and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.