- Goto the project (JeffFerguson.Gepsio project) and change the "Target Framework" to ".NET Framework 4".
- Add the following code to XbrlSchema.cs file:
using System.Net.Cache; // This line added for caching support
//...
public class XbrlSchema
{
//...
private XmlUrlResolver thisXmlUrlResolver;
//...
internal XbrlSchema(XbrlFragment ContainingXbrlFragment,
string SchemaFilename, string BaseDirectory)
{
thisContainingXbrlFragment = ContainingXbrlFragment;
this.Path = GetFullSchemaPath(SchemaFilename, BaseDirectory);
try
{
var schemaReader = XmlTextReader.Create(this.Path);
thisXmlSchema = XmlSchema.Read(schemaReader, null);
thisXmlSchemaSet = new XmlSchemaSet();
///---- START caching with XmlUrlResolver
thisXmlUrlResolver = new XmlUrlResolver();
thisXmlUrlResolver.CachePolicy = new
RequestCachePolicy(RequestCacheLevel.CacheIfAvailable);
thisXmlSchemaSet.XmlResolver = thisXmlUrlResolver;
///----- END caching with XmlUrlResolver
thisXmlSchemaSet.Add(thisXmlSchema);
thisXmlSchemaSet.Compile();
//...
A side note: the CachePolicy member of the XmlUrlResolver class is not available in .NET Framework version < 4.0 . That's the reason why you have to switch the project to .NET Framework 4.0.
Perhaps, you're not aware of this: the call to XmlSchemaSet.Add() will traverse every linked XSD schemas until all of them are resolved. Now, if the location of the schemas are remote, that incurs very high penalty to the speed of your application and that wastes unnecessary bandwidth. In this case, schema caching comes to the rescue.
Post a Comment
No comments:
Post a Comment