Example #1
0
        private Source augmentSource(Source source)
        {
            if (validation != SchemaValidationMode.None)
            {
                source = AugmentedSource.makeAugmentedSource(source);
                if (validation == SchemaValidationMode.Strict)
                {
                    ((AugmentedSource)source).setSchemaValidationMode(Validation.STRICT);
                }
                else
                {
                    ((AugmentedSource)source).setSchemaValidationMode(Validation.LAX);
                }
            }
            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).setTreeModel([email protected]_TREE);
                }
                else
                {
                    ((AugmentedSource)source).setTreeModel([email protected]_TREE);
                }
            }
            if (lineNumbering)
            {
                source = AugmentedSource.makeAugmentedSource(source);
                ((AugmentedSource)source).setLineNumbering(true);
            }
            if (dtdValidation)
            {
                source = AugmentedSource.makeAugmentedSource(source);
                ((AugmentedSource)source).setDTDValidationMode(Validation.STRICT);
            }
            return(source);
        }
Example #2
0
        // 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());
                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));
        }
Example #3
0
 private Source augmentSource(Source source)
 {
     if (validation != SchemaValidationMode.None)
     {
         source = AugmentedSource.makeAugmentedSource(source);
         if (validation == SchemaValidationMode.Strict)
         {
             ((AugmentedSource)source).setSchemaValidationMode(Validation.STRICT);
         }
         else
         {
             ((AugmentedSource)source).setSchemaValidationMode(Validation.LAX);
         }
     }
     if (whitespacePolicy != WhitespacePolicy.PreserveAll)
     {
         source = AugmentedSource.makeAugmentedSource(source);
         if (whitespacePolicy == WhitespacePolicy.StripIgnorable)
         {
             ((AugmentedSource)source).setStripSpace(Whitespace.IGNORABLE);
         }
         else
         {
             ((AugmentedSource)source).setStripSpace(Whitespace.ALL);
         }
     }
     if (lineNumbering)
     {
         source = AugmentedSource.makeAugmentedSource(source);
         ((AugmentedSource)source).setLineNumbering(true);
     }
     if (dtdValidation)
     {
         source = AugmentedSource.makeAugmentedSource(source);
         ((AugmentedSource)source).setDTDValidationMode(Validation.STRICT);
     }
     return(source);
 }