private void SetNumLink(int start, int end) { string numLinks = string.Empty; System.Xml.XmlNode node = doc.GetByID("labForNum"); if (node != null) { string activeCss = doc.GetAttrValue(node, "active"); System.Xml.XmlNode newNode = null; for (int i = end; i >= start; i--) { doc.Set("labNum", SetType.A, i.ToString(), URLPara.Replace("{0}", i.ToString())); newNode = node.Clone(); if (i == PageIndex && activeCss.Length > 0) { doc.Set(newNode, SetType.Class, activeCss); } doc.InsertAfter(newNode, node); } doc.Remove(node); } }
private static void ReplaceItemRef(XHtmlAction view, XmlNodeList list, bool isBreak, int loopCount) { //处理Shared目录下的节点替换。 if (list != null && list.Count > 0) { if (loopCount > 50) { throw new Exception("Reference loop : " + list[0].InnerXml); } string itemref = "itemref"; for (int i = 0; i < list.Count; i++) { string itemValue = list[i].Attributes[itemref].Value; if (!string.IsNullOrEmpty(itemValue)) { bool isOK = false; string[] items = itemValue.Split('.'); if (items.Length == 1)// 只一个节点,从当前节点寻找。 { XmlNode xNode = view.Get(items[0]); if (xNode != null) { view.ReplaceNode(xNode, list[i]); view.Remove(xNode);//从自己拿节点的,需要移除 isOK = true; } } else { XHtmlAction sharedView = GetSharedView(items[0], view.FileName);//找到masterView if (sharedView != null) { XmlNode xNode = sharedView.Get(items[1]);//找到被替换的节点 if (xNode != null) { view.InsertAfter(xNode, list[i]); //先插入节点。 XmlNodeList childNodeList = view.GetList("*", itemref, list[i].NextSibling); //检测内部是否有引用指向外部。 if (childNodeList != null && childNodeList.Count > 0) { loopCount++; ReplaceItemRef(view, childNodeList, true, loopCount); //下次跳出,避免死循环。 } view.Remove(list[i]); //移除节点 isOK = true; } } } if (!isOK) { view.Remove(list[i]);//移除没有引用的节点 // view.RemoveAttr(list[i], itemref); } } } loopCount++; if (!isBreak)//避免死循环。 { ReplaceItemRef(view, view.GetList("*", itemref), isBreak, loopCount); } } }