Create() public static method

Return an XmlNavigatorFilter that skips over nodes that do not match the specified name.
public static Create ( string localName, string namespaceUri ) : XmlNavigatorFilter
localName string
namespaceUri string
return XmlNavigatorFilter
Exemplo n.º 1
0
        //-----------------------------------------------
        // Constructors
        //-----------------------------------------------

        /// <summary>
        /// This constructor is internal so that external users cannot construct it (and therefore we do not have to test it separately).
        /// </summary>
        internal XmlQueryRuntime(XmlQueryStaticData data, object defaultDataSource, XmlResolver dataSources, XsltArgumentList argList, XmlSequenceWriter seqWrt)
        {
            Debug.Assert(data != null);
            string[]             names   = data.Names;
            Int32Pair[]          filters = data.Filters;
            WhitespaceRuleLookup wsRules;
            int i;

            // Early-Bound Library Objects
            wsRules       = (data.WhitespaceRules != null && data.WhitespaceRules.Count != 0) ? new WhitespaceRuleLookup(data.WhitespaceRules) : null;
            _ctxt         = new XmlQueryContext(this, defaultDataSource, dataSources, argList, wsRules);
            _xsltLib      = null;
            _earlyInfo    = data.EarlyBound;
            _earlyObjects = (_earlyInfo != null) ? new object[_earlyInfo.Length] : null;

            // Global variables and parameters
            _globalNames  = data.GlobalNames;
            _globalValues = (_globalNames != null) ? new object[_globalNames.Length] : null;

            // Names
            _nameTableQuery = _ctxt.QueryNameTable;
            _atomizedNames  = null;

            if (names != null)
            {
                // Atomize all names in "nameTableQuery".  Use names from the default data source's
                // name table when possible.
                XmlNameTable nameTableDefault = _ctxt.DefaultNameTable;
                _atomizedNames = new string[names.Length];

                if (nameTableDefault != _nameTableQuery && nameTableDefault != null)
                {
                    // Ensure that atomized names from the default data source are added to the
                    // name table used in this query
                    for (i = 0; i < names.Length; i++)
                    {
                        string name = nameTableDefault.Get(names[i]);
                        _atomizedNames[i] = _nameTableQuery.Add(name ?? names[i]);
                    }
                }
                else
                {
                    // Enter names into nametable used in this query
                    for (i = 0; i < names.Length; i++)
                    {
                        _atomizedNames[i] = _nameTableQuery.Add(names[i]);
                    }
                }
            }

            // Name filters
            _filters = null;
            if (filters != null)
            {
                // Construct name filters.  Each pair of integers in the filters[] array specifies the
                // (localName, namespaceUri) of the NameFilter to be created.
                _filters = new XmlNavigatorFilter[filters.Length];

                for (i = 0; i < filters.Length; i++)
                {
                    _filters[i] = XmlNavNameFilter.Create(_atomizedNames[filters[i].Left], _atomizedNames[filters[i].Right]);
                }
            }

            // Prefix maping lists
            _prefixMappingsList = data.PrefixMappingsList;

            // Xml types
            _types = data.Types;

            // Xml collations
            _collations = data.Collations;

            // Document ordering
            _docOrderCmp = new DocumentOrderComparer();

            // Indexes
            _indexes = null;

            // Output construction
            _stkOutput = new Stack <XmlQueryOutput>(16);
            _output    = new XmlQueryOutput(this, seqWrt);
        }
        //-----------------------------------------------
        // Constructors
        //-----------------------------------------------

        /// <summary>
        /// This constructor is internal so that external users cannot construct it (and therefore we do not have to test it separately).
        /// </summary>
        internal XmlQueryRuntime(XmlILCommand cmd, object defaultDataSource, XmlResolver dataSources, XsltArgumentList argList, XmlSequenceWriter seqWrt)
        {
            Debug.Assert(cmd != null, "Command object must be non-null");
            string[]             names   = cmd.Names;
            Int32Pair[]          filters = cmd.Filters;
            WhitespaceRuleLookup wsRules;
            int i;

            this.cmd = cmd;

            // Early-Bound Library Objects
            wsRules           = (cmd.WhitespaceRules.Count != 0) ? new WhitespaceRuleLookup(cmd.WhitespaceRules) : null;
            this.ctxt         = new XmlQueryContext(this, defaultDataSource, dataSources, argList, wsRules);
            this.xsltLib      = null;
            this.earlyInfo    = cmd.EarlyBound;
            this.earlyObjects = (this.earlyInfo != null) ? new object[earlyInfo.Length] : null;

            // Global variables and parameters
            this.globalNames  = cmd.GlobalNames;
            this.globalValues = (this.globalNames != null) ? new object[this.globalNames.Length] : null;

            // Names
            this.nameTableQuery = this.ctxt.QueryNameTable;
            this.atomizedNames  = null;

            if (names != null)
            {
                // Atomize all names in "nameTableQuery".  Use names from the default data source's
                // name table when possible.
                XmlNameTable nameTableDefault = ctxt.DefaultNameTable;
                this.atomizedNames = new string[names.Length];

                if (nameTableDefault != this.nameTableQuery && nameTableDefault != null)
                {
                    // Ensure that atomized names from the default data source are added to the
                    // name table used in this query
                    for (i = 0; i < names.Length; i++)
                    {
                        string name = nameTableDefault.Get(names[i]);
                        this.atomizedNames[i] = this.nameTableQuery.Add(name ?? names[i]);
                    }
                }
                else
                {
                    // Enter names into nametable used in this query
                    for (i = 0; i < names.Length; i++)
                    {
                        this.atomizedNames[i] = this.nameTableQuery.Add(names[i]);
                    }
                }
            }

            // Name filters
            this.filters = null;
            if (filters != null)
            {
                // Construct name filters.  Each pair of integers in the filters[] array specifies the
                // (localName, namespaceUri) of the NameFilter to be created.
                this.filters = new XmlNavigatorFilter[filters.Length];

                for (i = 0; i < filters.Length; i++)
                {
                    this.filters[i] = XmlNavNameFilter.Create(this.atomizedNames[filters[i].Left], this.atomizedNames[filters[i].Right]);
                }
            }

            // Prefix maping lists
            this.prefixMappingsList = cmd.PrefixMappingsList;

            // Xml types
            this.types = cmd.Types;

            // Xml collations
            this.collations = cmd.Collations;

            // Document ordering
            this.docOrderCmp = new DocumentOrderComparer();

            // Indexes
            this.indexes = null;

            // Output construction
            this.stkOutput = new Stack <XmlQueryOutput>(16);
            this.output    = new XmlQueryOutput(this, seqWrt);
        }