Exemplo n.º 1
0
        /*
         * public MarcNode SelectSingleNode(string strXpath)
         * {
         *  MarcNavigator nav = new MarcNavigator(this);
         *  XPathNodeIterator ni = nav.Select(strXpath);
         *  ni.MoveNext();
         *  return ((MarcNavigator)ni.Current).Item.MarcNode;
         * }
         * */

#if NO
        public MarcNodeList SelectNodes(string strPath)
        {
            string strFirstPart = GetFirstPart(ref strPath);

            if (strFirstPart == "/")
            {
                /*
                 * if (this.Parent == null)
                 *  return this.SelectNodes(strPath);
                 * */

                return(GetRootNode().SelectNodes(strPath));
            }

            if (strFirstPart == "..")
            {
                return(this.Parent.SelectNodes(strPath));
            }

            if (strFirstPart == ".")
            {
                return(this.SelectNodes(strPath));
            }

            // tagname[@attrname='']
            string strTagName   = "";
            string strCondition = "";

            int nRet = strFirstPart.IndexOf("[");

            if (nRet == -1)
            {
                strTagName = strFirstPart;
            }
            else
            {
                strCondition = strFirstPart.Substring(nRet + 1);
                if (strCondition.Length > 0)
                {
                    // 去掉末尾的']'
                    if (strCondition[strCondition.Length - 1] == ']')
                    {
                        strCondition.Substring(0, strCondition.Length - 1);
                    }
                }
                strTagName = strFirstPart.Substring(0, nRet);
            }

            MarcNodeList results = new MarcNodeList(null);

            for (int i = 0; i < this.ChildNodes.Count; i++)
            {
                MarcNode node = this.ChildNodes[i];
                Debug.Assert(node.Parent != null, "");
                if (strTagName == "*" || node.Name == strTagName)
                {
                    if (results.Parent == null)
                    {
                        results.Parent = node.Parent;
                    }
                    results.Add(node);
                }
            }


            if (String.IsNullOrEmpty(strPath) == true)
            {
                // 到了path的末级。用strFirstPart筛选对象
                return(results);
            }

            return(results.SelectNodes(strPath));
        }