// 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 = null; try { doc = config.buildDocument(source); } catch (net.sf.saxon.trans.XPathException e) { throw new StaticError(e); } return((XdmNode)XdmValue.Wrap(doc)); }
/// <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) { PullProvider pp = new DotNetPullProvider(reader); pp.setPipelineConfiguration(config.makePipelineConfiguration()); // pp = new PullTracer(pp); /* diagnostics */ PullSource psource = new PullSource(pp); psource.setSystemId(reader.BaseURI); this.source = psource; }
/// <summary> /// Compile a schema, delivered using an XmlReader. 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 XmlReader (that is, the XML parser) used to supply the source schema document</param> public void Compile(XmlReader reader) { PullProvider pp = new DotNetPullProvider(reader); pp.setPipelineConfiguration(config.makePipelineConfiguration()); // pp = new PullTracer(pp); /* diagnostics */ PullSource ss = new PullSource(pp); ss.setSystemId(reader.BaseURI); schemaManager.load(ss); }
/// <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) { PullProvider pp = new DotNetPullProvider(reader); PipelineConfiguration pipe = config.makePipelineConfiguration(); pipe.setUseXsiSchemaLocation(useXsiSchemaLocation); pipe.setRecoverFromValidationErrors(true); pp.setPipelineConfiguration(pipe); // pp = new PullTracer(pp); /* diagnostics */ PullSource psource = new PullSource(pp); psource.setSystemId(reader.BaseURI); this.source = psource; }
/// <summary> /// Load an XML document, delivered using an XmlReader. /// </summary> /// <remarks> /// <para>The XmlReader is responsible for parsing the document; this method builds a tree /// representation of the document (in an internal Saxon format) and returns its document node. /// The XmlReader is not required to perform validation but it must expand any entity references. /// Saxon uses the properties of the <c>XmlReader</c> as supplied.</para> /// <para>Use of a plain <c>XmlTextReader</c> is discouraged, because it does not expand entity /// references. This should only be used if you know in advance that the document will contain /// no entity references (or perhaps if your query or stylesheet is not interested in the content /// of text and attribute nodes). Instead, with .NET 1.1 use an <c>XmlValidatingReader</c> (with <c>ValidationType</c> /// set to <c>None</c>). The constructor for <c>XmlValidatingReader</c> is obsolete in .NET 2.0, /// but the same effect can be achieved by using the <c>Create</c> method of <c>XmlReader</c> with /// appropriate <c>XmlReaderSettings</c></para> /// <para>Conformance with the W3C specifications requires that the <c>Normalization</c> property /// of an <c>XmlTextReader</c> should be set to <c>true</c>. However, Saxon does not insist /// on this.</para> /// <para>If the <c>XmlReader</c> performs schema validation, Saxon will ignore any resulting type /// information. Type information can only be obtained by using Saxon's own schema validator, which /// will be run if the <c>SchemaValidationMode</c> property is set to <c>Strict</c> or <c>Lax</c></para> /// <para>Note that the Microsoft <c>System.Xml</c> parser does not report whether attributes are /// defined in the DTD as being of type <c>ID</c> and <c>IDREF</c>. This is true whether or not /// DTD-based validation is enabled. This means that such attributes are not accessible to the /// <c>id()</c> and <c>idref()</c> functions.</para> /// <para>Note that setting the <c>XmlResolver</c> property of the <c>DocumentBuilder</c> /// has no effect when this method is used; if an <c>XmlResolver</c> is required, it must /// be set on the <c>XmlReader</c> itself.</para> /// </remarks> /// <param name="reader">The XMLReader that supplies the parsed XML source</param> /// <returns>An <c>XdmNode</c>, the document node at the root of the tree of the resulting /// in-memory document /// </returns> public XdmNode Build(XmlReader reader) { PullProvider pp = new DotNetPullProvider(reader); pp.setPipelineConfiguration(config.makePipelineConfiguration()); // pp = new PullTracer(pp); /* diagnostics */ Source source = new PullSource(pp); source.setSystemId(reader.BaseURI); source = augmentSource(source); DocumentInfo doc = config.buildDocument(source); return((XdmNode)XdmValue.Wrap(doc)); }
// Build a document from a given stream, with the base URI supplied // as an extra argument internal XdmNode Build(Stream input, Uri baseUri) { Source source; if (processor.GetProperty("http://saxon.sf.net/feature/preferJaxpParser") == "true") { source = new StreamSource(new DotNetInputStream(input), baseUri.ToString()); } else { XmlReader parser = new XmlTextReader(baseUri.ToString(), input); ((XmlTextReader)parser).Normalization = true; switch (whitespacePolicy) { case WhitespacePolicy.PreserveAll: ((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.All; break; case WhitespacePolicy.StripAll: ((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.None; break; case WhitespacePolicy.StripIgnorable: ((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.Significant; break; } if (xmlResolver != null) { ((XmlTextReader)parser).XmlResolver = xmlResolver; } // Always need a validating parser, because that's the only way to get entity references expanded parser = new XmlValidatingReader(parser); if (dtdValidation) { ((XmlValidatingReader)parser).ValidationType = ValidationType.DTD; } else { ((XmlValidatingReader)parser).ValidationType = ValidationType.None; } 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, delivered using an XmlReader. 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 XmlReader (that is, the XML parser) used to supply the source schema document</param> public void Compile(XmlReader reader) { PullProvider pp = new DotNetPullProvider(reader); pp.setPipelineConfiguration(config.makePipelineConfiguration()); // pp = new PullTracer(pp); /* diagnostics */ PullSource ss = new PullSource(pp); ss.setSystemId(reader.BaseURI); if (errorList == null) { config.addSchemaSource(ss); } else { config.addSchemaSource(ss, new ErrorGatherer(errorList)); } }
/// <summary> /// Load an XML document, delivered using an XmlReader. /// </summary> /// <remarks> /// <para>The XmlReader is responsible for parsing the document; this method builds a tree /// representation of the document (in an internal Saxon format) and returns its document node. /// The XmlReader is not required to perform validation but it must expand any entity references. /// Saxon uses the properties of the <c>XmlReader</c> as supplied.</para> /// <para>Use of a plain <c>XmlTextReader</c> is discouraged, because it does not expand entity /// references. This should only be used if you know in advance that the document will contain /// no entity references (or perhaps if your query or stylesheet is not interested in the content /// of text and attribute nodes). Instead, with .NET 1.1 use an <c>XmlValidatingReader</c> (with <c>ValidationType</c> /// set to <c>None</c>). The constructor for <c>XmlValidatingReader</c> is obsolete in .NET 2.0, /// but the same effect can be achieved by using the <c>Create</c> method of <c>XmlReader</c> with /// appropriate <c>XmlReaderSettings</c></para> /// <para>Conformance with the W3C specifications requires that the <c>Normalization</c> property /// of an <c>XmlTextReader</c> should be set to <c>true</c>. However, Saxon does not insist /// on this.</para> /// <para>If the <c>XmlReader</c> performs schema validation, Saxon will ignore any resulting type /// information. Type information can only be obtained by using Saxon's own schema validator, which /// will be run if the <c>SchemaValidationMode</c> property is set to <c>Strict</c> or <c>Lax</c></para> /// <para>Note that the Microsoft <c>System.Xml</c> parser does not report whether attributes are /// defined in the DTD as being of type <c>ID</c> and <c>IDREF</c>. This is true whether or not /// DTD-based validation is enabled. This means that such attributes are not accessible to the /// <c>id()</c> and <c>idref()</c> functions.</para> /// <para>Note that setting the <c>XmlResolver</c> property of the <c>DocumentBuilder</c> /// has no effect when this method is used; if an <c>XmlResolver</c> is required, it must /// be set on the <c>XmlReader</c> itself.</para> /// </remarks> /// <param name="reader">The XMLReader that supplies the parsed XML source</param> /// <returns>An <c>XdmNode</c>, the document node at the root of the tree of the resulting /// in-memory document /// </returns> public XdmNode Build(XmlReader reader) { PullProvider pp = new DotNetPullProvider(reader); pp.setPipelineConfiguration(config.makePipelineConfiguration()); // pp = new PullTracer(pp); /* diagnostics */ Source source = new PullSource(pp); source.setSystemId(reader.BaseURI); source = augmentSource(source); DocumentInfo doc = null; try { doc = config.buildDocument(source); } catch (net.sf.saxon.trans.XPathException e) { throw new StaticError(e); } return((XdmNode)XdmValue.Wrap(doc)); }
/// <summary> /// Compile a schema, delivered using an XmlReader. 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. /// 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> public void Compile(XmlReader reader) { if (reader is XmlTextReader) { ((XmlTextReader)reader).Normalization = true; reader = new XmlValidatingReader(reader); ((XmlValidatingReader)reader).ValidationType = ValidationType.None; } PullProvider pp = new DotNetPullProvider(reader); pp.setPipelineConfiguration(config.makePipelineConfiguration()); // pp = new PullTracer(pp); /* diagnostics */ PullSource ss = new PullSource(pp); ss.setSystemId(reader.BaseURI); if (errorList == null) { config.addSchemaSource(ss); } else { config.addSchemaSource(ss, new ErrorGatherer(errorList)); } }
/// <summary> /// Load an XML document, delivered using an XmlReader. /// </summary> /// <remarks> /// <para>The XmlReader is responsible for parsing the document; this method builds a tree /// representation of the document (in an internal Saxon format) and returns its document node. /// The XmlReader is not required to perform validation but it must expand any entity references. /// Saxon uses the properties of the <c>XmlReader</c> as supplied.</para> /// <para>Use of a plain <c>XmlTextReader</c> is discouraged, because it does not expand entity /// references. This should only be used if you know in advance that the document will contain /// no entity references (or perhaps if your query or stylesheet is not interested in the content /// of text and attribute nodes). Instead, with .NET 1.1 use an <c>XmlValidatingReader</c> (with <c>ValidationType</c> /// set to <c>None</c>). The constructor for <c>XmlValidatingReader</c> is obsolete in .NET 2.0, /// but the same effect can be achieved by using the <c>Create</c> method of <c>XmlReader</c> with /// appropriate <c>XmlReaderSettings</c></para> /// <para>Conformance with the W3C specifications requires that the <c>Normalization</c> property /// of an <c>XmlTextReader</c> should be set to <c>true</c>. However, Saxon does not insist /// on this.</para> /// <para>If the <c>XmlReader</c> performs schema validation, Saxon will ignore any resulting type /// information. Type information can only be obtained by using Saxon's own schema validator, which /// will be run if the <c>SchemaValidationMode</c> property is set to <c>Strict</c> or <c>Lax</c></para> /// <para>Note that the Microsoft <c>System.Xml</c> parser does not report whether attributes are /// defined in the DTD as being of type <c>ID</c> and <c>IDREF</c>. This is true whether or not /// DTD-based validation is enabled. This means that such attributes are not accessible to the /// <c>id()</c> and <c>idref()</c> functions.</para> /// </remarks> /// <param name="reader">The XMLReader that supplies the parsed XML source</param> /// <returns>An <c>XdmNode</c>, the document node at the root of the tree of the resulting /// in-memory document /// </returns> public XdmNode Build(XmlReader reader) { PullProvider pp = new DotNetPullProvider(reader); pp.setPipelineConfiguration(config.makePipelineConfiguration()); // pp = new PullTracer(pp); /* diagnostics */ Source source = new PullSource(pp); source.setSystemId(reader.BaseURI); source = augmentSource(source); DocumentInfo doc = new StaticQueryContext(config).buildDocument(source); return (XdmNode)XdmValue.Wrap(doc); }
/// <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) { PullProvider pp = new DotNetPullProvider(reader); PipelineConfiguration pipe = config.makePipelineConfiguration(); pipe.setUseXsiSchemaLocation(useXsiSchemaLocation); pp.setPipelineConfiguration(pipe); // pp = new PullTracer(pp); /* diagnostics */ PullSource psource = new PullSource(pp); psource.setSystemId(reader.BaseURI); this.source = psource; }
/// <summary> /// Compile a schema, delivered using an XmlReader. 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 XmlReader (that is, the XML parser) used to supply the source schema document</param> public void Compile(XmlReader reader) { PullProvider pp = new DotNetPullProvider(reader); pp.setPipelineConfiguration(config.makePipelineConfiguration()); // pp = new PullTracer(pp); /* diagnostics */ PullSource ss = new PullSource(pp); ss.setSystemId(reader.BaseURI); if (errorList == null) { config.addSchemaSource(ss); } else { config.addSchemaSource(ss, new ErrorGatherer(errorList)); } }