public static GetSchemas ( ) : |
||
return |
/// <summary> /// Validation callback for a validating XML reader. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">Any data pertinent to the event.</param> private void HandleValidation(object sender, ValidationEventArgs args) { if (args.Severity == XmlSeverityType.Error) { XmlSchemaException ex = args.Exception; XmlReader xmlReader = (XmlReader)sender; if (!NamespaceParserRegistry.GetSchemas().Contains(xmlReader.NamespaceURI) && ex is XmlSchemaValidationException) { // try wellknown parsers bool registered = NamespaceParserRegistry.RegisterWellknownNamespaceParserType(xmlReader.NamespaceURI); if (registered) { throw new RetryParseException(); } } throw ex; } else { #region Instrumentation if (log.IsWarnEnabled) { log.Warn( "Ignored XML validation warning: " + args.Message, args.Exception); } #endregion } }
private XmlReader CreateValidatingReader(MemoryStream stream) { XmlReader reader; if (SystemUtils.MonoRuntime) { reader = XmlUtils.CreateReader(stream); } else { #if !NET_2_0 // only because 1.0/1.1 don't pass the sender into the handler callback... ValidationEventHandlerWrapper validationEventHandlerWrapper = new ValidationEventHandlerWrapper(this); reader = XmlUtils.CreateValidatingReader(stream, Resolver, NamespaceParserRegistry.GetSchemas(), new ValidationEventHandler(validationEventHandlerWrapper.HandleValidation)); validationEventHandlerWrapper.Reader = reader; #else reader = XmlUtils.CreateValidatingReader(stream, Resolver, NamespaceParserRegistry.GetSchemas(), HandleValidation); #endif } #region Instrumentation if (log.IsDebugEnabled) { log.Debug("Using the following XmlReader implementation : " + reader.GetType()); } return(reader); #endregion }
public void CanLoadSchemaImportingOtherSchemaByRelativePath() { string schemaLocation = TestResourceLoader.GetAssemblyResourceUri(this.GetType(), "NamespaceParserRegistryTests_TestSchema.xsd"); NamespaceParserRegistry.RegisterParser(new TestNamespaceParser(), "http://www.example.com/brief", schemaLocation); XmlReader vr = XmlUtils.CreateValidatingReader(new StringResource( @"<?xml version='1.0' encoding='UTF-8' ?> <brief class='foo' /> ").InputStream, NamespaceParserRegistry.GetSchemas(), null); ConfigXmlDocument newDoc = new ConfigXmlDocument(); newDoc.Load(vr); }
/// <summary> /// Validation callback for a validating XML reader. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">Any data pertinent to the event.</param> private void HandleValidation(object sender, ValidationEventArgs args) { if (args.Severity == XmlSeverityType.Error) { XmlSchemaException ex = args.Exception; XmlReader xmlReader = (XmlReader)sender; if (!NamespaceParserRegistry.GetSchemas().Contains(xmlReader.NamespaceURI) #if NET_2_0 && ex is XmlSchemaValidationException #endif ) { // try wellknown parsers bool registered = NamespaceParserRegistry.RegisterWellknownNamespaceParserType(xmlReader.NamespaceURI); if (registered) { throw new RetryParseException(); } } #if !NET_2_0 // ignore validation errors for well-known 'xml' namespace. This seems to be a bug in net 1.0 + 1.1 if (ex.Message.IndexOf("http://www.w3.org/XML/1998/namespace:") > -1) { return; } #endif throw ex; } else { #region Instrumentation if (log.IsWarnEnabled) { log.Warn( "Ignored XML validation warning: " + args.Message, args.Exception); } #endregion } }
private XmlReader CreateValidatingReader(MemoryStream stream) { XmlReader reader; if (SystemUtils.MonoRuntime) { reader = XmlUtils.CreateReader(stream); } else { reader = XmlUtils.CreateValidatingReader(stream, Resolver, NamespaceParserRegistry.GetSchemas(), HandleValidation); } #region Instrumentation if (log.IsDebugEnabled) { log.Debug("Using the following XmlReader implementation : " + reader.GetType()); } return(reader); #endregion }