public XmlCtl eachAllChild(string strNode, Action <int, XmlCtl> fun) { try { XmlCtl ele = child(strNode); for (int i = 0; i < ele.doc.ChildNodes.Count; ++i) { if (ele.doc.ChildNodes[i].NodeType != XmlNodeType.Element) { continue; } XmlCtl eleChild = copySelf(); eleChild.doc = ele.doc.ChildNodes[i]; //Debug.WriteLine(ele.doc.ChildNodes[i].NodeType); fun?.Invoke(i, eleChild); } } catch (Exception) { } return(this); }
public string attr(string strNode, string initData = "") { string result = ""; try { var idx = strNode.LastIndexOf('.'); if (idx < 0) { if (doc != null && doc.NodeType == XmlNodeType.Element) { XmlElement eleNode = (XmlElement)doc; if (!eleNode.HasAttribute(strNode)) { return(initData); } else { result = eleNode.GetAttribute(strNode); } return(result); } } else { XmlCtl ele = child(strNode.Substring(0, idx)); result = ele.attr(strNode.Substring(idx + 1), initData); } } catch (Exception) { setAttr(strNode, initData); return(initData); } if (result == "") { return(initData); } return(result); }
public override void parse(XmlCtl node) { mapVar[node.attr("name")] = cvt(node.value()); }
public abstract void parse(XmlCtl node);
public XmlCtl child(string strNode) { if (strNode == "") { return(this); } string[] arr = strNode.Split('.'); List <string> lstNode = new List <string>(arr); XmlNode temp = null; if (doc == null) { temp = root.SelectSingleNode(lstNode[0]); if (temp == null) { XmlElement ele = root.CreateElement(lstNode[0]); root.AppendChild(ele); temp = ele; } lstNode.RemoveAt(0); } else { temp = doc; } for (int i = 0; i < lstNode.Count; ++i) { string strOneNode = lstNode[i].Trim(); if (strOneNode == "") { return(this); } if (strOneNode[strOneNode.Length - 1] == ']') { int idx = strOneNode.IndexOf('['); if (idx <= 0) { return(this); } //get name string eleName = strOneNode.Substring(0, idx); //get index int nodeIdx = 0; if (!Int32.TryParse(strOneNode.Substring(idx + 1, strOneNode.Length - 1 - idx - 1), out nodeIdx)) { return(this); } if (nodeIdx < 0) { return(this); } //get lst XmlNodeList xLst = temp.SelectNodes(eleName); if (xLst == null || nodeIdx >= xLst.Count) { int newIdx = 0; if (xLst == null || xLst.Count <= 0) { newIdx = 0; } else { newIdx = xLst.Count; } for (int j = newIdx; j < nodeIdx + 1; ++j) { XmlElement ele = root.CreateElement(eleName); temp.AppendChild(ele); if (j == nodeIdx) { temp = ele; } } //return this; } else { temp = xLst[nodeIdx]; } } else { XmlNodeList xLst = temp.SelectNodes(strOneNode); if (xLst == null || xLst.Count <= 0) { XmlElement ele = root.CreateElement(strOneNode); temp.AppendChild(ele); temp = ele; //return this; } else { temp = xLst[0]; } } } if (temp == doc) { return(this); } XmlCtl result = copySelf(); result.doc = temp; return(result); //XmlNodeList lis = doc.GetElementsByTagName("Name"); //return this; }