-
public class XmlTreeModel {
-
-
#region Private Variable
-
private int _indexid;
-
private int _parentid;
-
private string _title = string.Empty;
-
private System.
Collections.
Generic.
List<xmltreemodel> _childnodes =
new System.
Collections.
Generic.
List</xmltreemodel><xmltreemodel>
();
-
private XmlTreeModel _parent = null;
-
private string _pathoftreeindex = string.Empty;
-
private string _pathoftitle = string.Empty;
-
private string _xmltag = string.Empty;
-
private string _pathseparator = "/"; // 搭配TreeView.PathSeparator使用
-
#endregion
-
-
#region public enum XmlTreeModelPathType {...}
-
public enum XmlTreeModelPathType {
-
PathOfTreeIndex = 0,
-
PathOfTitle = 1
-
}
-
#endregion
-
-
#region Public Property
-
public int IndexID { get { return _indexid; } }
-
public int ParentID { get { return _parentid; } }
-
public string Title { get { return _title; } }
-
public System.Collections.Generic.List</xmltreemodel><xmltreemodel> ChildNodes { get { return _childnodes; } }
-
public XmlTreeModel Parent { get { return _parent; } }
-
public string XmlTagName { get { return _xmltag; } }
-
public string PathSeparator {
-
get { return _pathseparator; }
-
set { _pathseparator = value; }
-
}
-
#endregion
-
-
#region 多型 public XmlTreeModel()
-
-
#region public XmlTreeModel(int indexid, string title) {...}
-
public XmlTreeModel(int indexid, string title) {
-
_indexid = indexid;
-
_title = title;
-
_pathoftitle = title;
-
_pathoftreeindex = indexid.ToString();
-
_xmltag = _title.Replace(' ', '_');
-
}
-
#endregion
-
-
#region public XmlTreeModel(int indexid, string title, string xmltagname) {...}
-
public XmlTreeModel(int indexid, string title, string xmltagname) {
-
_indexid = indexid;
-
_title = title;
-
_pathoftitle = title;
-
_pathoftreeindex = indexid.ToString();
-
_xmltag = xmltagname;
-
}
-
#endregion
-
-
#endregion
-
-
#region public XmlTreeModel AppendChild(XmlTreeModel item) {...}
-
public XmlTreeModel AppendChild(XmlTreeModel item) {
-
item._parent = this;
-
item._parentid = this._indexid;
-
item._pathseparator = this._pathseparator;
-
item._pathoftreeindex = this._pathoftreeindex + this._pathseparator + item._pathoftreeindex;
-
item._pathoftitle = this._pathoftitle + this._pathseparator + item._pathoftitle;
-
_childnodes.Add(item);
-
return item;
-
}
-
#endregion
-
-
#region 多型 public string ToXMLString()
-
-
#region public string ToXMLString() {...}
-
public string ToXMLString() {
-
return ToXMLString(false);
-
}
-
#endregion
-
-
#region public string ToXMLString(bool bInsCrLf) {...}
-
public string ToXMLString(bool bInsCrLf) {
-
string cr = (bInsCrLf) ? "\n" : "";
-
string sXml = "< " + this._xmltag + " IndexID=\"" + this._indexid + "\" Title=\"" + this._title + "\"";
-
if (this._childnodes.Count == 0) {
-
sXml += " />" + cr;
-
} else {
-
sXml += ">" + cr;
-
foreach (XmlTreeModel xtm in this._childnodes) {
-
string nXml = xtm.ToXMLString(bInsCrLf);
-
sXml += nXml;
-
}
-
sXml += "" + cr;
-
}
-
return sXml;
-
}
-
#endregion
-
-
#endregion
-
-
#region public XmlTreeModel SearchNode(string treePath, XmlTreeModelPathType pt) {...}
-
public XmlTreeModel SearchNode(string treePath, XmlTreeModelPathType pt) {
-
string chkPath = string.Empty;
-
switch (pt) {
-
case XmlTreeModelPathType.PathOfTreeIndex:
-
chkPath = this._pathoftreeindex;
-
break;
-
case XmlTreeModelPathType.PathOfTitle:
-
chkPath=this._pathoftitle;
-
break;
-
default:
-
break;
-
}
-
if (chkPath == treePath)
-
return this;
-
foreach (XmlTreeModel xtm in _childnodes) {
-
XmlTreeModel node = xtm.SearchNode(treePath, pt);
-
if (node != null)
-
return node;
-
}
-
return null;
-
}
-
#endregion
-
-
}