示例#1
0
        /// <summary>
        /// 初始化一个 MarcNavigator 类的实例。
        /// </summary>
        /// <param name="navigator">参考的 MarcNavigator 对象</param>
        public MarcNavigator(MarcNavigator navigator)
        {
            //StreamUtil.WriteText("I:\\debug.txt","进到 构造函数XmlEditorNavigator(navigator)里\r\n");

            this.m_navigatorState = new NavigatorState(navigator.m_navigatorState);
            this.m_nametable      = (NameTable)navigator.NameTable;
        }
示例#2
0
        /// <summary>
        /// 初始化一个 MarcNavigator 类的实例。
        /// </summary>
        /// <param name="navigator">参考的 MarcNavigator 对象</param>
        public MarcNavigator(MarcNavigator navigator) 
		{
			//StreamUtil.WriteText("I:\\debug.txt","进到 构造函数XmlEditorNavigator(navigator)里\r\n");

            this.m_navigatorState = new NavigatorState(navigator.m_navigatorState);
            this.m_nametable = (NameTable)navigator.NameTable;
		}
示例#3
0
        // 对一批互相没有树重叠关系的对象进行筛选
        static MarcNodeList simpleSelect(MarcNodeList source,
                                         string strXPath,
                                         int nMaxCount = -1)
        {
            // 准备一个模拟的记录节点
            // MarcRecord record = new MarcRecord();
            MarcNode temp_root = new MarcNode();

            temp_root.Name = "temp";

            // 保存下集合中所有的Parent指针
            List <MarcNode> parents = new List <MarcNode>();

            foreach (MarcNode node in source)
            {
                // 保存指针
                parents.Add(node.Parent);

                // 建立父子关系,但原来位置的ChidNodes并不摘除
                temp_root.ChildNodes.baseAdd(node);
                node.Parent = temp_root;
                // Debug.Assert(node.Parent == temp_root, "");
            }
            Debug.Assert(parents.Count == source.count, "");

            try
            {
                MarcNodeList results = new MarcNodeList();

                MarcNavigator nav = new MarcNavigator(temp_root);  // 出发点在模拟的记录节点上

                XPathNodeIterator ni = nav.Select(strXPath);
                while (ni.MoveNext() && (nMaxCount == -1 || results.count < nMaxCount))
                {
                    NaviItem item = ((MarcNavigator)ni.Current).Item;
                    if (item.Type != NaviItemType.Element)
                    {
                        throw new Exception("xpath '" + strXPath + "' 命中了非元素类型的节点,这是不允许的");
                        continue;
                    }
                    if (results.indexOf(item.MarcNode) == -1)   // 不重复的才加入
                    {
                        results.add(item.MarcNode);
                    }
                }
                return(results);
            }
            finally
            {
                // 恢复原先的 Parent 指针
                Debug.Assert(parents.Count == source.count, "");
                for (int i = 0; i < source.count; i++)
                {
                    source[i].Parent = parents[i];
                }
            }
        }
示例#4
0
文件: MarcNode.cs 项目: renyh/dp2mini
        // 针对DOM树进行 XPath 筛选
        // parameters:
        //      nMaxCount    至多选择开头这么多个元素。-1表示不限制
        /// <summary>
        /// 用 XPath 字符串选择节点
        /// </summary>
        /// <param name="strXPath">XPath 字符串</param>
        /// <param name="nMaxCount">限制命中的最多节点数。-1表示不限制</param>
        /// <returns>被选中的节点集合</returns>
        public MarcNodeList select(string strXPath, int nMaxCount /* = -1*/)
        {
            MarcNodeList results = new MarcNodeList();

            MarcNavigator nav = new MarcNavigator(this);  // 出发点在当前对象

            XPathNodeIterator ni = nav.Select(strXPath);

            while (ni.MoveNext() && (nMaxCount == -1 || results.count < nMaxCount))
            {
                NaviItem item = ((MarcNavigator)ni.Current).Item;
                if (item.Type != NaviItemType.Element)
                {
                    // if (bSkipNoneElement == false)
                    throw new Exception("xpath '" + strXPath + "' 命中了非元素类型的节点,这是不允许的");
                    continue;
                }
                results.add(item.MarcNode);
            }
            return(results);
        }
示例#5
0
        // 针对DOM树进行 XPath 筛选
        // parameters:
        //      nMaxCount    至多选择开头这么多个元素。-1表示不限制
        /// <summary>
        /// 用 XPath 字符串选择节点
        /// </summary>
        /// <param name="strXPath">XPath 字符串</param>
        /// <param name="nMaxCount">限制命中的最多节点数。-1表示不限制</param>
        /// <returns>被选中的节点集合</returns>
        public MarcNodeList select(string strXPath, int nMaxCount/* = -1*/)
        {
            MarcNodeList results = new MarcNodeList();

            MarcNavigator nav = new MarcNavigator(this);  // 出发点在当前对象

            XPathNodeIterator ni = nav.Select(strXPath);
            while (ni.MoveNext() && (nMaxCount == -1 || results.count < nMaxCount))
            {
                NaviItem item = ((MarcNavigator)ni.Current).Item;
                if (item.Type != NaviItemType.Element)
                {
                    // if (bSkipNoneElement == false)
                        throw new Exception("xpath '"+strXPath+"' 命中了非元素类型的节点,这是不允许的");
                    continue;
                }
                results.add(item.MarcNode);
            }
            return results;
        }