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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:35:35+00:00 2026-05-12T05:35:35+00:00

EDIT See my solution below /EDIT I have a Visual Studio solution with two

  • 0

EDIT See my solution below /EDIT

I have a Visual Studio solution with two projects.

  • Project 1 (call it ReferencedProject) contains an XML schema file (ReferencedSchema.xsd).
  • Project 2 (call it MainProject) contains ReferencedProject as a reference. MainProject also has a schema file (MainSchema.xsd).

MainSchema.xsd contains the following code:

<?xml version="1.0"?>
<xs:schema
  xmlns="main"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:tns="main"
  targetNamespace="main"
  elementFormDefault="qualified">
  <xs:include schemaLocation="ReferencedSchema.xsd" />
  ...
</xs:schema>

Because ReferencedSchema.xsd is not in the same folder (it’s not even in the same project), I get an error saying “ReferencedSchema.xsd could not be resolved.” Makes sense.

If I edit the xs:include element to this…

<xs:include schemaLocation="../../ReferencedProject/Data/ReferencedSchema.xsd" />

…the error goes away. However, notice that I’ve provided a relative path to the schema that will only work within my solution’s folder hierarchy. That’s great when I’m viewing the schema in the editor but not so great when I compile my project. If I look in my “bin” folder after compiling, the folder hierarchy is completely different (the two xsd files actually end up in the same folder).

I tried to get around this using Visual Studio’s “Add Existing Item As Link” feature, putting a shortcut to the ReferencedSchema.xsd file in the same folder as my main schema file, but that didn’t work. The XSD validator apparently isn’t capable of pretending the link is the actual file.

So, my problem is that there doesn’t seem to be any uri I can provide for schemaLocation that will be valid in both situations (within the solution explorer and during runtime). Does anyone have any suggestions?

Thanks!

EDIT

I decided to go with this:

<xs:include schemaLocation="../../ReferencedProject/Data/ReferencedSchema.xsd" />

This is correct as long as I’m viewing things within Visual Studio, incorrect when running my code.

To make it work at runtime as well, I dynamically replace the schemaLocation with the correct relative reference as follows:

public class UriReplacingXmlValidator
{
    public virtual XDocument Validate(
        string dataFolderName,
        string baseDataFolderName,
        string xmlFileName,
        string schemaFileName,
        string baseSchemaFileName)
    {
        string rootFolderPath = Environment.CurrentDirectory + Path.DirectorySeparatorChar;
        string dataFolderPath = rootFolderPath + Path.DirectorySeparatorChar + dataFolderName;
        string baseDataFolderPath = rootFolderPath + Path.DirectorySeparatorChar + baseDataFolderName;
        string xmlPath = dataFolderPath + Path.DirectorySeparatorChar + xmlFileName;
        string schemaPath = dataFolderName + Path.DirectorySeparatorChar + schemaFileName;
        string baseSchemaPath = baseDataFolderName + Path.DirectorySeparatorChar + baseSchemaFileName;
        XDocument xmlDocument = XDocument.Load(xmlPath);
        XDocument schemaDocument = XDocument.Load(schemaPath);
        ResetBaseSchemaLocation(schemaDocument, baseSchemaPath);
        XmlValidator validator = new XmlValidator();
        bool isValid = validator.Validate(xmlDocument, schemaDocument);
        if (isValid)
            return xmlDocument;
        else
            return null;
    }

    protected virtual void ResetBaseSchemaLocation(XDocument schemaDocument, string baseSchemaPath)
    {
        XNamespace ns = "http://www.w3.org/2001/XMLSchema";
        XAttribute attribute = schemaDocument.Element(ns + "schema").Element(ns + "redefine").Attribute("schemaLocation");
        attribute.Value = baseSchemaPath;
    }

I went with this solution because everything now works whether I’m viewing my XML and XSD files in Visual Studio or running/debugging my app.

  • 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-12T05:35:35+00:00Added an answer on May 12, 2026 at 5:35 am

    XSD only supports URI locations, not path location. This means that file:///C:/path/to/VS/Projects/ReferencedProject/Data/ReferencedSchema.xsd is valid, but not ../../ReferencedProject/Data/ReferencedSchema.xsd.

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

Sidebar

Ask A Question

Stats

  • Questions 179k
  • Answers 179k
  • 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 Try this (untested): public class AllowAccessAttribute : AuthorizeAttribute { public… May 12, 2026 at 3:49 pm
  • Editorial Team
    Editorial Team added an answer trac. The best there is (IMHO). Visit trac-hacks.org to get… May 12, 2026 at 3:49 pm
  • Editorial Team
    Editorial Team added an answer Use logging.exception from within the except: handler/block to log the… May 12, 2026 at 3:49 pm

Related Questions

I have two C DLLs that I need to access in the same executable.
I am trying to disable a number of text boxes intended for displaying data
I'm writing a C parser using PLY, and recently ran into a problem. This
First, I will outline my issue in case someone has an alternate fix. The

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.