/// <summary> /// Compile a stylesheet, delivered using an XmlReader. /// </summary> /// <remarks> /// The <c>XmlReader</c> is responsible for parsing the document; this method builds a tree /// representation of the document (in an internal Saxon format) and compiles it. /// If the <c>XmlReader</c> is an <c>XmlTextReader</c>, Saxon will set its <c>Normalization</c> /// property to true, and will wrap it in a (non-validating) <c>XmlValidatingReader</c> to ensure /// that entity references are expanded. /// </remarks> /// <remarks> /// If the <c>XmlReader</c> has a <c>BaseUri</c> property, then that property determines /// the base URI of the stylesheet module, which is used when resolving any <c>xsl:include</c> /// or <c>xsl:import</c> declarations. If the <c>XmlReader</c> has no <c>BaseUri</c> /// property, then the <c>BaseUri</c> property of the <c>Compiler</c> is used instead. /// An <c>ArgumentNullException</c> is thrown if this property has not been supplied. /// </remarks> /// <returns>An <c>XsltExecutable</c> which represents the compiled stylesheet object. /// The XsltExecutable may be run as many times as required, in the same or a different /// thread. The <c>XsltExecutable</c> is not affected by any changes made to the <c>XsltCompiler</c> /// once it has been compiled.</returns> public XsltExecutable Compile(XmlReader reader) { if (reader is XmlTextReader) { ((XmlTextReader)reader).Normalization = true; reader = new XmlValidatingReader(reader); ((XmlValidatingReader)reader).ValidationType = ValidationType.None; } DotNetPullProvider pp = new DotNetPullProvider(reader); JPipelineConfiguration pipe = config.makePipelineConfiguration(); pipe.setLocationProvider(pp); pp.setPipelineConfiguration(pipe); // pp = new PullTracer(pp); /* diagnostics */ JPullSource source = new JPullSource(pp); String baseu = reader.BaseURI; if (baseu == null || baseu == String.Empty) { // if no baseURI is supplied by the XmlReader, use the one supplied to this Compiler if (baseUri == null) { throw new ArgumentNullException("BaseUri"); } baseu = baseUri.ToString(); pp.setBaseURI(baseu); } source.setSystemId(baseu); PreparedStylesheet pss = (PreparedStylesheet)factory.newTemplates(source, info); return(new XsltExecutable(pss)); }
/// <summary> /// Compile a stylesheet, retrieving the source using a URI. /// </summary> /// <remarks> /// The document located via the URI is parsed using the <c>System.Xml</c> parser. This /// URI is used as the base URI of the stylesheet: the <c>BaseUri</c> property of the /// <c>Compiler</c> is ignored. /// </remarks> /// <param name="uri">The URI identifying the location where the stylesheet document can be /// found</param> /// <returns>An <c>XsltExecutable</c> which represents the compiled stylesheet object. /// The XsltExecutable may be run as many times as required, in the same or a different /// thread. The <c>XsltExecutable</c> is not affected by any changes made to the <c>XsltCompiler</c> /// once it has been compiled.</returns> public XsltExecutable Compile(Uri uri) { Object obj = XmlResolver.GetEntity(uri, "application/xml", Type.GetType("System.IO.Stream")); if (obj is Stream) { try { XmlReaderSettings settings = new XmlReaderSettings(); settings.ProhibitDtd = false; // must expand entity references settings.XmlResolver = XmlResolver; settings.IgnoreWhitespace = false; settings.ValidationType = ValidationType.None; XmlReader parser = XmlReader.Create((Stream)obj, settings, uri.ToString()); //XmlReader parser = new XmlTextReader(uri.ToString(), (Stream)obj); //((XmlTextReader)parser).Normalization = true; //((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.All; //((XmlTextReader)parser).XmlResolver = XmlResolver; // Always need a validating parser, because that's the only way to get entity references expanded //parser = new XmlValidatingReader(parser); //((XmlValidatingReader)parser).ValidationType = ValidationType.None; JPullSource source = new JPullSource(new DotNetPullProvider(parser)); PreparedStylesheet pss = (PreparedStylesheet)factory.newTemplates(source, info); return(new XsltExecutable(pss)); } finally { ((Stream)obj).Close(); } } else { throw new ArgumentException("Invalid type of result from XmlResolver.GetEntity: " + obj); } }
/// <summary> /// Compile a schema, delivered using an <c>XmlReader</c>. The resulting schema components are added /// to the cache. /// </summary> /// <remarks> /// The <c>XmlReader</c> is responsible for parsing the document; this method builds a tree /// representation of the document (in an internal Saxon format) and compiles it. /// The <c>XmlReader</c> is used as supplied; it is the caller's responsibility to ensure that /// its settings are appropriate for parsing a schema document (for example, that entity references /// are expanded and whitespace is retained). /// </remarks> /// <param name="reader">The <c>XmlReader</c> (that is, the XML parser) used to supply the source schema document</param> public void Compile(XmlReader reader) { JPullProvider pp = new JDotNetPullProvider(reader); pp.setPipelineConfiguration(config.makePipelineConfiguration()); // pp = new PullTracer(pp); /* diagnostics */ JPullSource ss = new JPullSource(pp); ss.setSystemId(reader.BaseURI); schemaManager.load (ss); }
/// <summary> /// Add an instance document to the list of documents to be validated /// </summary> /// <param name="reader">Source document supplied as an <c>XmlReader</c></param> public void AddSource(XmlReader reader) { JPullProvider pp = new JDotNetPullProvider(reader); JPipelineConfiguration pipe = config.makePipelineConfiguration(); pipe.setUseXsiSchemaLocation(schemaValidator.isUseXsiSchemaLocation()); pp.setPipelineConfiguration(pipe); // pp = new PullTracer(pp); /* diagnostics */ JPullSource psource = new JPullSource(pp); psource.setSystemId(reader.BaseURI); sources.Add(psource); }
/// <summary> /// Supply the instance document to be validated, in the form of an XmlReader. /// </summary> /// <remarks> /// The XmlReader is responsible for parsing the document; this method validates it. /// </remarks> /// <param name="reader">The <c>XmlReader</c> used to read and parse the instance /// document being validated. This is used as supplied. For conformance, use of a /// plain <c>XmlTextReader</c> is discouraged, because it does not expand entity /// references. This may cause validation failures. /// </param> public void SetSource(XmlReader reader) { JPullProvider pp = new JDotNetPullProvider(reader); JPipelineConfiguration pipe = config.makePipelineConfiguration(); pipe.setUseXsiSchemaLocation(useXsiSchemaLocation); pp.setPipelineConfiguration(pipe); // pp = new PullTracer(pp); /* diagnostics */ JPullSource psource = new JPullSource(pp); psource.setSystemId(reader.BaseURI); this.source = psource; sources.Clear(); }
/// <summary> /// Compile a stylesheet, delivered using an XmlReader. /// </summary> /// <remarks> /// The <c>XmlReader</c> is responsible for parsing the document; this method builds a tree /// representation of the document (in an internal Saxon format) and compiles it. /// The <c>XmlReader</c> will be used as supplied; it is the caller's responsibility to /// ensure that the settings of the <c>XmlReader</c> are consistent with the requirements /// of the XSLT specification (for example, that entity references are expanded and whitespace /// is preserved). /// </remarks> /// <remarks> /// If the <c>XmlReader</c> has a <c>BaseUri</c> property, then that property determines /// the base URI of the stylesheet module, which is used when resolving any <c>xsl:include</c> /// or <c>xsl:import</c> declarations. If the <c>XmlReader</c> has no <c>BaseUri</c> /// property, then the <c>BaseUri</c> property of the <c>Compiler</c> is used instead. /// An <c>ArgumentNullException</c> is thrown if this property has not been supplied. /// </remarks> /// <param name="reader">The XmlReader (that is, the XML parser) used to supply the document containing /// the principal stylesheet module.</param> /// <returns>An <c>XsltExecutable</c> which represents the compiled stylesheet object. /// The XsltExecutable may be run as many times as required, in the same or a different /// thread. The <c>XsltExecutable</c> is not affected by any changes made to the <c>XsltCompiler</c> /// once it has been compiled.</returns> public XsltExecutable Compile(XmlReader reader) { DotNetPullProvider pp = new DotNetPullProvider(reader); JPipelineConfiguration pipe = config.makePipelineConfiguration(); pipe.setLocationProvider(pp); pp.setPipelineConfiguration(pipe); // pp = new PullTracer(pp); /* diagnostics */ JPullSource source = new JPullSource(pp); String baseu = reader.BaseURI; if (baseu == null || baseu == String.Empty) { // if no baseURI is supplied by the XmlReader, use the one supplied to this Compiler if (baseUri == null) { throw new ArgumentNullException("BaseUri"); } baseu = baseUri.ToString(); pp.setBaseURI(baseu); } source.setSystemId(baseu); PreparedStylesheet pss = (PreparedStylesheet)factory.newTemplates(source, info); return new XsltExecutable(pss); }
/// <summary> /// Compile a stylesheet, retrieving the source using a URI. /// </summary> /// <remarks> /// The document located via the URI is parsed using the <c>System.Xml</c> parser. This /// URI is used as the base URI of the stylesheet: the <c>BaseUri</c> property of the /// <c>Compiler</c> is ignored. /// </remarks> /// <param name="uri">The URI identifying the location where the stylesheet document can be /// found</param> /// <returns>An <c>XsltExecutable</c> which represents the compiled stylesheet object. /// The XsltExecutable may be run as many times as required, in the same or a different /// thread. The <c>XsltExecutable</c> is not affected by any changes made to the <c>XsltCompiler</c> /// once it has been compiled.</returns> public XsltExecutable Compile(Uri uri) { Object obj = XmlResolver.GetEntity(uri, "application/xml", Type.GetType("System.IO.Stream")); if (obj is Stream) { try { XmlReaderSettings settings = new XmlReaderSettings(); settings.ProhibitDtd = false; // must expand entity references settings.XmlResolver = XmlResolver; settings.IgnoreWhitespace = false; settings.ValidationType = ValidationType.None; XmlReader parser = XmlReader.Create((Stream)obj, settings, uri.ToString()); //XmlReader parser = new XmlTextReader(uri.ToString(), (Stream)obj); //((XmlTextReader)parser).Normalization = true; //((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.All; //((XmlTextReader)parser).XmlResolver = XmlResolver; // Always need a validating parser, because that's the only way to get entity references expanded //parser = new XmlValidatingReader(parser); //((XmlValidatingReader)parser).ValidationType = ValidationType.None; JPullSource source = new JPullSource(new DotNetPullProvider(parser)); PreparedStylesheet pss = (PreparedStylesheet)factory.newTemplates(source, info); return new XsltExecutable(pss); } finally { ((Stream)obj).Close(); } } else { throw new ArgumentException("Invalid type of result from XmlResolver.GetEntity: " + obj); } }
/// <summary> /// Compile a stylesheet, delivered using an XmlReader. /// </summary> /// <remarks> /// The <c>XmlReader</c> is responsible for parsing the document; this method builds a tree /// representation of the document (in an internal Saxon format) and compiles it. /// If the <c>XmlReader</c> is an <c>XmlTextReader</c>, Saxon will set its <c>Normalization</c> /// property to true, and will wrap it in a (non-validating) <c>XmlValidatingReader</c> to ensure /// that entity references are expanded. /// </remarks> /// <remarks> /// If the <c>XmlReader</c> has a <c>BaseUri</c> property, then that property determines /// the base URI of the stylesheet module, which is used when resolving any <c>xsl:include</c> /// or <code>xsl:import</code> declarations. If the <c>XmlReader</c> has no <c>BaseUri</c> /// property, then the <c>BaseUri</c> property of the <c>Compiler</c> is used instead. /// </remarks> /// <returns>An <c>XsltExecutable</c> which represents the compiled stylesheet object. /// The XsltExecutable may be run as many times as required, in the same or a different /// thread. The <c>XsltExecutable</c> is not affected by any changes made to the <c>XsltCompiler</c> /// once it has been compiled.</returns> public XsltExecutable Compile(XmlReader reader) { if (reader is XmlTextReader) { ((XmlTextReader)reader).Normalization = true; reader = new XmlValidatingReader(reader); ((XmlValidatingReader)reader).ValidationType = ValidationType.None; } DotNetPullProvider pp = new DotNetPullProvider(reader); JPipelineConfiguration pipe = config.makePipelineConfiguration(); pipe.setLocationProvider(pp); pp.setPipelineConfiguration(pipe); // pp = new PullTracer(pp); /* diagnostics */ JPullSource source = new JPullSource(pp); String baseu = reader.BaseURI; if (baseu == null || baseu == String.Empty) { // if no baseURI is supplied by the XmlReader, use the one supplied to this Compiler baseu = baseUri.ToString(); pp.setBaseURI(baseu); } source.setSystemId(baseu); PreparedStylesheet pss = (PreparedStylesheet)factory.newTemplates(source, info); return new XsltExecutable(pss); }