Reputation: 365
I have a problem in validating XML against XSD when the base XSD is importing some other XSDs from site. For example, for the following XSD item, it is throwing error.
<link:linkbase xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:link = 'http://www.xbrl.org/2003/linkbase' xmlns:xbrli = 'http://www.xbrl.org/2003/instance' xmlns:xlink = 'http://www.w3.org/1999/xlink' xsi:schemaLocation = 'http://www.xbrl.org/2003/linkbase http://www.xbrl.org/2003/xbrl-linkbase-2003-12-31.xsd' >
Is there any solution for importing the XSD by release version of DLLs. I am using the following C# code for validating XML against the XSD. The same is working when I execute it through Visual Studio.
var schemas = new XmlSchemaSet();
schemas.Add(null, xsdFilePath);
var readerSettings = new XmlReaderSettings();
readerSettings.ValidationType = ValidationType.Schema;
readerSettings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation;
readerSettings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
readerSettings.Schemas.Add(schemas);
using (var xmlReader = XmlReader.Create(xmlFilePath, readerSettings))
{
while (xmlReader.Read())
{
}
}
Upvotes: 0
Views: 821
Reputation: 5141
Obviously, the parser cannot find the schema xbrl-instance-2003-12-31
. From the w3 schema specs:
(
xsi:schemaLocation
) records the author's warrant with pairs of URI references (one for the namespace name, and one for a hint as to the location of a schema document defining names for that namespace name)
that is, the first part of your schemaLocation definition xbrl.org/2003/xbrl-instance-2003-12-31.xsd
is the namespace. If the parser doesn't already know where to find the schema for such namespace, you must provide it with the location. For example:
<xs:import
namespace='xbrl.org/2003/instance'
schemaLocation='xbrl.org/2003/xbrl-instance-2003-12-31.xsd http:/xbrl.org/2003/xbrl-instance-2003-12-31.xsd'/>
Upvotes: 1