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 706785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:12:17+00:00 2026-05-14T04:12:17+00:00

Here is my first attempt at validating XML with XSD. The XML file to

  • 0

Here is my first attempt at validating XML with XSD.

The XML file to be validated:

<?xml version="1.0" encoding="utf-8" ?>
<config xmlns="Schemas" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="config.xsd">
  <levelVariant>
    <filePath>SampleVariant</filePath>
  </levelVariant>
  <levelVariant>
    <filePath>LegendaryMode</filePath>
  </levelVariant>
  <levelVariant>
    <filePath>AmazingMode</filePath>
  </levelVariant>
</config>

The XSD, located in “Schemas/config.xsd” relative to the XML file to be validated:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:element name="config">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="levelVariant">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="filePath" type="xs:anyURI">
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Right now, I just want to validate the XML file precisely as it appears currently. Once I understand this better, I’ll expand more. Do I really need so many lines for something as simple as the XML file as it currently exists?

The validation code in C#:

        public void SetURI(string uri)
        {
            XElement toValidate = XElement.Load(Path.Combine(PATH_TO_DATA_DIR, uri) + ".xml");

// begin confusion

       // exception here
       string schemaURI = toValidate.Attributes("xmlns").First().ToString() 
                              + toValidate.Attributes("xsi:noNamespaceSchemaLocation").First().ToString();
        XmlSchemaSet schemas = new XmlSchemaSet();
        schemas.Add(null, schemaURI);

        XDocument toValidateDoc = new XDocument(toValidate);
        toValidateDoc.Validate(schemas, null);
// end confusion

            root = toValidate;
        }

Running the above code gives this exception:

The ':' character, hexadecimal value 0x3A, cannot be included in a name.

Any illumination would be appreciated.

  • 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-05-14T04:12:18+00:00Added an answer on May 14, 2026 at 4:12 am

    Rather than using the XDocument.Validate extension method, I would use an XmlReader which can be configured to process an inline schema via XmlReaderSettings. You could do some thing like the following code.

    public void VerifyXmlFile(string path)
    {
        // configure the xmlreader validation to use inline schema.
        XmlReaderSettings config = new XmlReaderSettings();
        config.ValidationType = ValidationType.Schema;
        config.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
        config.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
        config.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation;
        config.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
    
        // Get the XmlReader object with the configured settings.
        XmlReader reader = XmlReader.Create(path, config);
    
        // Parsing the file will cause the validation to occur.
        while (reader.Read()) ;
    
    }
    
    private void ValidationCallBack(object sender, ValidationEventArgs vea)
    {
        if (vea.Severity == XmlSeverityType.Warning)
            Console.WriteLine(
                "\tWarning: Matching schema not found.  No validation occurred. {0}",
                vea.Message);
        else
            Console.WriteLine("\tValidation error: {0}", vea.Message);
    
    }
    

    The code above assumes the following using statements.

    using System.Xml;
    using System.Xml.Schema;
    

    Just to keep this simple I did not return a boolean or a collection of validation errors, you could easily modify this to do so.

    Note: I modified your config.xml and config.xsd to get them to validate. These are the changes I made.

    config.xsd:

    <xs:element maxOccurs="unbounded" name="levelVariant">
    

    config.xml:

    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="config.xsd">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 342k
  • Answers 342k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Please see Stage::stageWidth and Stage::stageHeight. May 14, 2026 at 5:11 am
  • Editorial Team
    Editorial Team added an answer Working Code Try this: public class TestExceptions extends Exception {… May 14, 2026 at 5:11 am
  • Editorial Team
    Editorial Team added an answer I do not believe Lucene supports anything like this, nor… May 14, 2026 at 5:11 am

Related Questions

This is my first attempt at a plugin but I think I'm missing the
Here is my current code (that i am very proud of for my first
Has anyone attempted using perlembed in Mono on Linux? Here is the link: perlembed
I'm trying to use the Class methods of prototype.js to manage my object hierarchy
I have a ModalPopupExtender that allows a customer to apply payment info. It has

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.