Exemplo n.º 1
0
        // 在当前集合中每个元素的DOM位置 下级开头 插入新元素
        // 参见 MarcQuery::prepend() 函数的注释
        // 最后返回当前集合
        /// <summary>
        /// 在当前集合的每个元素的 DOM 位置的下级开头插入根据指定的源字符串构造的新元素
        /// </summary>
        /// <param name="strSourceText">源字符串</param>
        /// <returns>当前集合</returns>
        public MarcNodeList prepend(string strSourceText)
        {
            if (this.count == 0 || string.IsNullOrEmpty(strSourceText))
            {
                return(this);
            }

            if (this[0].NodeType == NodeType.None)
            {
                throw new ArgumentException("不允许在 None 节点的 下级开头 添加任何节点");
            }
            if (this[0].NodeType == NodeType.Subfield)
            {
                throw new ArgumentException("不允许在 子字段 节点的 下级开头 添加任何节点。因为子字段本身就是末级节点,不允许出现下级节点");
            }

            MarcNodeList source_nodes = null;
            string       strLeading   = "";

            if (this[0].NodeType == NodeType.Record)
            {
                source_nodes = MarcQuery.createFields(strSourceText);
            }
            else if (this[0].NodeType == NodeType.Field)
            {
                source_nodes = MarcQuery.createSubfields(strSourceText, out strLeading);
                // leading要追加到目标集合的最后一个元素的Content末尾
                if (string.IsNullOrEmpty(strLeading) == false)
                {
                    this.last()[0].Content += strLeading;
                }
            }
            else
            {
                throw new Exception("未知的对象类型 '" + this[0].NodeType.ToString() + "'");
            }

            MarcQuery.prepend(source_nodes, this);
            return(this);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 将当前集合内的全部元素插入到指定的目标集合的 DOM 位置下级开头
 /// </summary>
 /// <param name="target_nodes">目标集合</param>
 /// <returns>当前集合</returns>
 public MarcNodeList prependTo(MarcNodeList target_nodes)
 {
     MarcQuery.prepend(this, target_nodes);
     return(this);
 }
Exemplo n.º 3
0
 // 在当前集合中每个元素的DOM位置 下级开头 插入源集合内的元素
 // 参见 MarcQuery::prepend() 函数的注释
 // 最后返回当前集合
 /// <summary>
 /// 在当前集合的每个元素的 DOM 位置的下级开头插入源集合内的元素
 /// </summary>
 /// <param name="source_nodes">源集合</param>
 /// <returns>当前集合</returns>
 public MarcNodeList prepend(MarcNodeList source_nodes)
 {
     MarcQuery.prepend(source_nodes, this);
     return(this);
 }