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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:58:23+00:00 2026-05-23T00:58:23+00:00

I am working with a fairly complex third-party XSD format – XSDs refer to

  • 0

I am working with a fairly complex third-party XSD format – XSDs refer to types in another XSD which refers to types in yet another XSD. I need to be able to validate XML against this format. I’ve been able to get this to validate using XML Spy but now we need a more automated approach.

I am loading the XSDs using a slightly more complex version of this code, but they are equivalent (as long as I haven’t made any typos):

string xmlFile = @"C:\tmp\testxml\Valid.xml";
string xsdFile = @"C:\tmp\testxml\DRO.xsd";

var schema = new XmlSchemaCollection();
var reader = new FileStream(xmlFile, FileMode.Open);
var validating = new XmlValidatingReader(reader, XmlNodeType.Element, null);

// Removed 3 other XSDs to simplify a bit, but are included in the real code
schema.Add("http://www.test.com/PTS/Formdom", @"C:\tmp\textxml\Formdom.xsd");
schema.Add("http://www.test.com/PTS/DRO", @"C:\tmp\textxml\DRO.xsd");

validating.ValidationType = ValidationType.Schema;
validating.ValidationEventHandler += validating_ValidationEventHandler;

while (validating.Read()) {} 

// More code removed

The XML file looks like this – I’ve trimmed it WAY down to just the section where the first error occurs:

<?xml version="1.0" encoding="UTF-8" ?>
 <dro:DRO 
xmlns:dro="http://www.test.com/PTS/DRO" 
xmlns:for="http://www.test.com/PTS/Formdom" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.test.com/PTS/DRO" >

    <dro:HeaderSection>
       <dro:VersionNumber>1.2</dor:VersionNumber>
    </dro:HeaderSection>
 </dro:DRO>

The DRO.XSD looks like this (again, heavily trimmed down):

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.test.com/PTS/DRO" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:FF="http://www.test.com/PTS/FormFields" 
xmlns:CD="http://www.test.com/PTS/Formdom" 
xmlns:CF="http://www.test.com/PTS/CommonFields" 
targetNamespace="http://www.test.com/PTS/DRO" 
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="http://www.test.com/PTS/FormFields" schemaLocation="FormFields.xsd"/>
<xs:import namespace="http://www.test.com/PTS/Formdom" schemaLocation="FormDom.xsd"/>
<xs:import namespace="http://www.test.com/PTS/CommonFields" schemaLocation="CommonFields.xsd"/>
<xs:element name="DRO">
<xs:complexType>
   <xs:sequence>
     <xs:element name="HeaderSection" type="HeaderSection"/>
       </xs:sequence>
    </xs:complexType>

I’m assuming the error is located in how the xmlns and targetNamespace stuff is configured and I’ve made sure that they match exactly (and that even the case is the same). I also made sure that when I add the schema in my C# the target namespace matches. In the code I show above I manually set the name but in the real code I extract the targetNamespace from the XSD and use that.

When I run the code I can successfully add all of the XSDs, but as soon as it starts reading the XML file it fails with these errors:

Could not find schema information for the element
‘http://www.test.com/PTS/DRO:DRO&#8217;
Could not find schema information for the element
‘http://www.test.com/PTS/DRO:HeaderSection&#8217;

(plus a ton of other similar errors)

I’m just not seeing what I need to do to make this work. Any ideas?

EDIT: I’ve gone back through this code again and realized I wasn’t actually doing anything with my schemas. I was adding them to a XmlSchemaCollection but I wasn’t attaching that to anything. I modified the code to use the XmlReaderSettings() class, then added the schemas to it’s Schema collection:

var settings = new XmlReaderSettings();
// Code removed
settings.Schema.Add("http://www.test.com/PTS/Formdom", @"C:\tmp\textxml\Formdom.xsd");
// Code removed
var validating = XmlReader.Create(reader, settings);

This looks like it’s actually working (yeah!). I’ve made small changes to the XML doc to get it to fail and it looks like it’s catching the errors.

  • 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-23T00:58:24+00:00Added an answer on May 23, 2026 at 12:58 am

    Trying adding these settings for the XmlValidatingReader.Settings

    XmlReaderSettings settings = new XmlReaderSettings();
    settings.ValidationType = ValidationType.Schema;
    settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
    settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation;
    
    validating.Settings = settings;
    

    schema.Add() is not required in this case, as the XmlSchemaValidationFlags.ProcessInlineSchema would process the inline schemas encountered during validation.

    More information

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

Sidebar

Related Questions

I'm working on a fairly complex project, a custom encryption routine if you will
I am working on a fairly complex Java application using Swing. On some occasions
I have a fairly complex multi-threaded Windows service working, but I can't figure out
I'm working on implementing a customized searchBar for a fairly complex table and have
I'm working on what is turning out to be a fairly complex SELECT query.
I am working with a fairly complex solution in Visual Studio 2008. It contains
I have the following function in access, which was working fairly well. But now
I've started working on a fairly complicated software. It is for a personal project,
I am working in Java on a fairly large project. My question is about
I am fairly comfortable with standalone Java app development, but will soon be working

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.