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

  • SEARCH
  • Home
  • 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 7735679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:33:41+00:00 2026-06-01T07:33:41+00:00

Problem: I am trying to validate an XML schema file against an XML instance

  • 0

Problem: I am trying to validate an XML schema file against an XML instance file using C#. However I keep getting these messages:

Could not find schema information for the element 'Courses'.
Could not find schema information for the element 'Course'.
Could not find schema information for the element 'Code'.
Could not find schema information for the attribute 'Undergrad'.
Could not find schema information for the element 'CourseName'.
Could not find schema information for the element 'Instructor'.
Could not find schema information for the element 'Name'.
Could not find schema information for the element 'First'.
Could not find schema information for the element 'Last'.
Could not find schema information for the element 'Contact'.
Could not find schema information for the attribute 'Office'.
Could not find schema information for the element 'Phone'.
Could not find schema information for the element 'Room'.
Could not find schema information for the element 'Cap'.

My schema file (tempuri.com is replaced by the real location in my actual file)

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema targetNamespace="http://www.tempuri.com/Courses3.xsd"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified"
    xmlns="http://www.tempuri.com/Courses3.xsd"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
  <!--definition of simple elements-->
  <xsd:element name="Cap" type="xsd:integer"/>
  <xsd:element name="Room" type="xsd:string"/>
  <xsd:element name="Phone" type="xsd:integer"/>
  <xsd:element name="First" type ="xsd:string"/>
  <xsd:element name="Last" type ="xsd:string"/>
  <xsd:element name="CourseName" type ="xsd:string"/>

  <!--definition of attributes-->
  <xsd:attribute name="Grad" type="xsd:string"/>
  <xsd:attribute name="Undergrad" type="xsd:string"/>
  <xsd:attribute name="Office" type="xsd:string"/>


  <!--definition of complext elements-->

  <!--Courses-->
  <xsd:element name="Courses">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="Course" minOccurs="0" maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

  <!--Course-->
  <xsd:element name="Course">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="Code" minOccurs="1" maxOccurs="1"/>
        <xsd:element ref="CourseName" minOccurs="1" maxOccurs="1"/>
        <xsd:element ref="Instructor" minOccurs="1" maxOccurs="1"/>
        <xsd:element ref="Room" minOccurs="0" maxOccurs="1"/>
        <xsd:element ref="Cap" minOccurs="1" maxOccurs="1"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

  <!--Code-->
  <xsd:element name="Code">
    <xsd:complexType>
      <xsd:attribute ref="Grad" use ="optional"/>
      <xsd:attribute ref="Undergrad" use ="optional"/>
    </xsd:complexType>
  </xsd:element>

  <!--Instructor-->
  <xsd:element name="Instructor">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="Name" minOccurs="1" maxOccurs="1"/>
        <xsd:element ref="Contact" minOccurs="0" maxOccurs="1"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

  <!--Name-->
  <xsd:element name="Name">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="First" minOccurs="1" maxOccurs="1"/>
        <xsd:element ref="Last" minOccurs="1" maxOccurs="1"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

  <!--Contact-->
  <xsd:element name="Contact">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="Phone" minOccurs="0" maxOccurs="1"/>
      </xsd:sequence>
      <xsd:attribute ref="Office" use ="optional"/>
    </xsd:complexType>
  </xsd:element>

</xsd:schema>

My XML instance:

<?xml version="1.0" encoding="utf-8"?>
<Courses>
  <Course>
    <Code Undergrad ="CSEXXX"/>
    <CourseName>
      Programming
    </CourseName>
    <Instructor>
      <Name>
        <First>
          Jim
        </First>
        <Last>
          Bob
        </Last>
      </Name>
      <Contact Office ="MLG562">
        <Phone>
          5555555555
        </Phone>
      </Contact>
    </Instructor>
    <Room>
      TLK130
    </Room>
    <Cap>
      70
    </Cap>
  </Course>

My C# validation methods:

public string CoursesVerification(string pXMLurl, string pXSDurl)
    {
        XmlValidatingReader vr = null;
        try
        {
            XmlTextReader nvr = new XmlTextReader(pXMLurl); //get xml file
            nvr.WhitespaceHandling = WhitespaceHandling.None;
            vr = new XmlValidatingReader(nvr); //wrap nvr in vr
            vr.Schemas.Add(GetTargetNamespace(pXSDurl), pXSDurl);
            vr.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
            while (vr.Read());
            return _VerifyString;
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
        finally
        {
            if (vr != null) vr.Close();
        }
    }

    static string GetTargetNamespace(string src)
    {
        XmlTextReader nvr = null;
        try
        {

            nvr = new XmlTextReader(src);
            nvr.WhitespaceHandling = WhitespaceHandling.None;
            while (nvr.Read())
            {
                if (nvr.NodeType == XmlNodeType.Element && nvr.LocalName == "schema")
                {
                    while (nvr.MoveToNextAttribute())
                    {
                        if (nvr.Name == "targetNamespace") return nvr.Value;
                    }
                }
            }
            return "";
        }
        finally
        {
            if (nvr != null) nvr.Close();
        }
    }

    static void ValidationCallBack(object sender, ValidationEventArgs e)
    {
        if (String.Compare(_VerifyString, "No Error") == 0) _VerifyString = e.Message + "\n";
        else _VerifyString += e.Message + "\n";
    }

I have been looking everywhere trying to figure out what I am overlooking. What am I doing wrong with this validation?

  • 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-01T07:33:43+00:00Added an answer on June 1, 2026 at 7:33 am

    Just a quick glance as I don’t have time to dig through everything, it looks like your XML file does not define a namespace, but your XSD does. That is probably a place to start looking. In your root element of your XML file, you need to specify the namespace.

    <Courses xmlns="http://www.tempuri.com/Courses3.xsd">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the XML::LibXML::Schema to validate a xml file against a xsd.
I am trying to validate xml files against a very large industrial schema using
I'm trying to find a way to validate a large XML file against an
I'm trying to validate my XML files from given XSD file with the following
I have a problem trying to validate a user value using the jQuery Validation
I'm using Java 5 javax.xml.validation.Validator to validate XML file. I've done it for one
I have a bit of problem when trying to validate my page as HTML5.
I have a strange problem. I am trying to validate one form sent through
I am trying to validate a few XML files and I'm failing due to
I'm trying to validate a form using the validate plugin for jquery. I want

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.