/// <summary> /// Supply the instance document to be validated in the form of a <c>Uri</c> reference /// </summary> /// <param name="uri">URI of the document to be validated</param> public void SetSource(Uri uri) { JStreamSource ss = new JStreamSource(uri.ToString()); JAugmentedSource aug = JAugmentedSource.makeAugmentedSource(ss); aug.setPleaseCloseAfterUse(true); this.source = aug; sources.Clear(); }
// Build a document from a given stream, with the base URI supplied // as an extra argument internal XdmNode Build(TextReader input, Uri baseUri) { Source source; if (processor.GetProperty("http://saxon.sf.net/feature/preferJaxpParser") == "true") { source = new StreamSource(new DotNetReader(input), baseUri.ToString()); source = AugmentedSource.makeAugmentedSource(source); ((AugmentedSource)source).setEntityResolver(new DotNetURIResolver(XmlResolver)); } else { XmlReaderSettings settings = new XmlReaderSettings(); settings.ProhibitDtd = false; // must expand entity references //((XmlTextReader)parser).Normalization = true; switch (whitespacePolicy) { case WhitespacePolicy.PreserveAll: settings.IgnoreWhitespace = false; //((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.All; break; case WhitespacePolicy.StripAll: settings.IgnoreWhitespace = true; //((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.None; break; case WhitespacePolicy.StripIgnorable: settings.IgnoreWhitespace = true; //((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.Significant; break; } if (xmlResolver != null) { settings.XmlResolver = xmlResolver; } settings.ValidationType = (dtdValidation ? ValidationType.DTD : ValidationType.None); XmlReader parser = XmlReader.Create(input, settings, baseUri.ToString()); source = new PullSource(new DotNetPullProvider(parser)); source.setSystemId(baseUri.ToString()); } source = augmentSource(source); DocumentInfo doc = config.buildDocument(source); return((XdmNode)XdmValue.Wrap(doc)); }
/// <summary> /// Compile a schema, retrieving the source using a URI. The resulting schema components are added /// to the cache. /// </summary> /// <remarks> /// The document located via the URI is parsed using the <c>System.Xml</c> parser. /// </remarks> /// <param name="uri">The URI identifying the location where the schema document can be /// found</param> public void Compile(Uri uri) { StreamSource ss = new StreamSource(uri.ToString()); JAugmentedSource aug = JAugmentedSource.makeAugmentedSource(ss); aug.setPleaseCloseAfterUse(true); if (errorList == null) { config.addSchemaSource(aug); } else { config.addSchemaSource(aug, new ErrorGatherer(errorList)); } }
/// <summary> /// Run the validation of the supplied source document, optionally /// writing the validated document to the supplied destination. /// </summary> public void Run() { JAugmentedSource aug = JAugmentedSource.makeAugmentedSource(source); aug.setSchemaValidationMode(lax ? JValidation.LAX : JValidation.STRICT); JReceiver receiver; JPipelineConfiguration pipe = config.makePipelineConfiguration(); if (destination == null) { receiver = new JSink(pipe); } else if (destination is Serializer) { receiver = ((Serializer)destination).GetReceiver(config); } else { Result result = destination.GetReceiver(pipe); if (result is JReceiver) { receiver = (JReceiver)result; } else { throw new ArgumentException("Unknown type of destination"); } } pipe.setUseXsiSchemaLocation(useXsiSchemaLocation); receiver.setPipelineConfiguration(pipe); JParseOptions parseOptions = null; if (errorList != null) { invalidityHandler = new net.sf.saxon.lib.InvalidityHandlerWrappingErrorListener(new ErrorGatherer(errorList)); } parseOptions = new JParseOptions(); parseOptions.setInvalidityHandler(invalidityHandler); JSender.send(aug, receiver, parseOptions); }
/// <summary> /// Run the validation of the supplied source document, optionally /// writing the validated document to the supplied destination. /// </summary> public void Run() { JAugmentedSource aug = JAugmentedSource.makeAugmentedSource(source); aug.setSchemaValidationMode(lax ? JValidation.LAX : JValidation.STRICT); JReceiver receiver; if (destination == null) { receiver = new Sink(); } else if (destination is Serializer) { receiver = ((Serializer)destination).GetReceiver(config); } else { Result result = destination.GetResult(); if (result is JReceiver) { receiver = (JReceiver)result; } else { throw new ArgumentException("Unknown type of destination"); } } PipelineConfiguration pipe = config.makePipelineConfiguration(); pipe.setUseXsiSchemaLocation(useXsiSchemaLocation); receiver.setPipelineConfiguration(pipe); if (errorList != null) { pipe.setErrorListener(new ErrorGatherer(errorList)); } Sender.send(aug, receiver, null); }
private Source augmentSource(Source source) { if (validation != SchemaValidationMode.None) { source = AugmentedSource.makeAugmentedSource(source); if (validation == SchemaValidationMode.Strict) { ((AugmentedSource)source).setSchemaValidationMode(JValidation.STRICT); } else if (validation == SchemaValidationMode.Lax) { ((AugmentedSource)source).setSchemaValidationMode(JValidation.LAX); } else if (validation == SchemaValidationMode.None) { ((AugmentedSource)source).setSchemaValidationMode(JValidation.STRIP); } else if (validation == SchemaValidationMode.Preserve) { ((AugmentedSource)source).setSchemaValidationMode(JValidation.PRESERVE); } } if (topLevelElement != null) { source = AugmentedSource.makeAugmentedSource(source); ((AugmentedSource)source).setTopLevelElement( new StructuredQName( topLevelElement.Prefix, topLevelElement.Uri, topLevelElement.LocalName)); } if (whitespacePolicy != WhitespacePolicy.PreserveAll) { source = AugmentedSource.makeAugmentedSource(source); if (whitespacePolicy == WhitespacePolicy.StripIgnorable) { ((AugmentedSource)source).setStripSpace(Whitespace.IGNORABLE); } else { ((AugmentedSource)source).setStripSpace(Whitespace.ALL); } } if (treeModel != TreeModel.Unspecified) { source = AugmentedSource.makeAugmentedSource(source); if (treeModel == TreeModel.TinyTree) { ((AugmentedSource)source).setModel(net.sf.saxon.om.TreeModel.TINY_TREE); } else if (treeModel == TreeModel.TinyTreeCondensed) { ((AugmentedSource)source).setModel(net.sf.saxon.om.TreeModel.TINY_TREE_CONDENSED); } else { ((AugmentedSource)source).setModel(net.sf.saxon.om.TreeModel.LINKED_TREE); } } if (lineNumbering) { source = AugmentedSource.makeAugmentedSource(source); ((AugmentedSource)source).setLineNumbering(true); } if (dtdValidation) { source = AugmentedSource.makeAugmentedSource(source); ((AugmentedSource)source).setDTDValidationMode(JValidation.STRICT); } return(source); }
/// <summary> /// Add an instance document to the list of documents to be validated /// </summary> /// <param name="uri">URI of the source document</param> public void AddSource(Uri uri) { JStreamSource ss = new JStreamSource(uri.ToString()); JAugmentedSource aug = JAugmentedSource.makeAugmentedSource(ss); aug.setPleaseCloseAfterUse(true); sources.Add(aug); }