Example #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ElementFragmentNs getElementFragmentNs()
        {
            if (this.ns == false)
                throw new NavException("getElementFragmentNS can only be called ");

            FastIntBuffer fib = new FastIntBuffer(3); // init size 8

            //fill the fib with integer 
            // first get the list of name space nodes 
            int[] ia = context;
            int d = ia[0]; // -1 for document node, 0 for root element;
            int c = getCurrentIndex2();


            int len = (c == 0 || c == rootIndex) ? 0 :
                (getTokenLength(c) & 0xffff); // get the length of qualified node

            // put the neighboring ATTR_NS nodes into the array
            // and record the total # of them	     
            int i = 0;
            int count = 0;
            if (d > 0)
            { // depth > 0 every node except document and root element
                int k = getCurrentIndex2() + 1;
                if (k < this.vtdSize)
                {
                    while (k < this.vtdSize)
                    {
                        int type = this.getTokenType(k);
                        if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS)
                        {
                            if (type == VTDNav.TOKEN_ATTR_NS)
                            {
                                fib.append(k);
                                //System.out.println(" ns name ==>" + toString(k));
                            }
                            k += 2;
                        }
                        else
                            break;
                        
                        //type = this.getTokenType(k);
                    }
                }
                count = fib.size_Renamed_Field;
                d--;
                while (d >= 0)
                {
                    // then search for ns node in the vinicity of the ancestor nodes
                    if (d > 0)
                    {
                        // starting point
                        k = ia[d] + 1;
                    }
                    else
                    {
                        // starting point
                        k = this.rootIndex + 1;
                    }
                    if (k < this.vtdSize)
                    {
                        while (k < this.vtdSize)
                        {
                            int type = this.getTokenType(k);
                            if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS)
                            {
                                bool unique = true;
                                if (type == VTDNav.TOKEN_ATTR_NS)
                                {
                                    for (int z = 0; z < fib.size_Renamed_Field; z++)
                                    {
                                        //System.out.println("fib size ==> "+fib.size_Renamed_Field);
                                        //if (fib.size_Renamed_Field == 4) ;
                                        if (matchTokens(fib.intAt(z), this, k))
                                        {
                                            unique = false;
                                            break;
                                        }

                                    }
                                    if (unique)
                                        fib.append(k);
                                }
                            }
                            k += 2;
                            //type = this.getTokenType(k);
                        }
                    }
                    d--;
                }
                // System.out.println("count ===> "+count);
                // then restore the name space node by shifting the array
                int newSz = fib.size_Renamed_Field - count;
                for (i = 0; i < newSz; i++)
                {
                    fib.modifyEntry(i, fib.intAt(i + count));
                }
                fib.size_Renamed_Field = newSz;
            }

            long l = getElementFragment();
            return new ElementFragmentNs(this, l, fib, len);
        }