public static string GetGrid(XmlObject obj, int index) { const string tpl = @"<div class=""ui-xmldoc"" id=""object_%object.key%""> <h2><a href=""#%object.key%"">%object.index%%object.name%<span class=""key"">(%object.key%)</span></a></h2> <p class=""descript"">描述:%object.descript%</p> <p class=""prop""> <table cellspacing=""1"" cellpadding=""0""> <tr><th class=""key"">属性键:</th><th class=""name"">属性名称:</th><th class=""descript"">备注:</th></tr> %object.prop% </table> </p> </div>"; StringBuilder sb = new System.Text.StringBuilder(); if (obj.Properties != null) { foreach (XmlObjectProperty p in obj.Properties) { sb.Append("<tr><td class=\"key\">").Append(p.Key) .Append("</td><td class=\"name\">").Append(p.Name).Append("</td><td class=\"descript\">") .Append(p.Descript).Append(" </td></tr>"); } } return tpl.Replace("%object.key%", obj.Key) .Replace("%object.index%", index < 1 ? "" : index.ToString()) .Replace("%object.name%", obj.Name) .Replace("%object.descript%", obj.Descript.Replace("\n", "<br />")) .Replace("%object.prop%", sb.ToString()); }
/// <summary> /// 获取所有对象 /// </summary> /// <returns></returns> public IEnumerable<XmlObject> GetObjects() { IList<XmlObjectProperty> prolist = new List<XmlObjectProperty>(); XmlNodeList nodes = this.rootNode.SelectNodes("object"); XmlObject obj; XmlNodeList proNodes; foreach (XmlNode node in nodes) { obj = new XmlObject(node.Attributes["key"].Value, node.Attributes["name"].Value, node.SelectSingleNode("descript").InnerText); proNodes = node.SelectNodes("properties/property"); prolist.Clear(); foreach (XmlNode n in proNodes) { prolist.Add(new XmlObjectProperty( n.Attributes["key"].Value, n.Attributes["name"].Value, n.InnerText)); } obj.Properties = prolist.ToArray(); yield return obj; } }
public XmlObject GetObject(string objectKey) { XmlNode node = this.rootNode.SelectSingleNode(String.Format("object[@key='{0}']", objectKey)); if (node == null) return null; IList<XmlObjectProperty> prolist = new List<XmlObjectProperty>(); XmlObject obj = new XmlObject(node.Attributes["key"].Value, node.Attributes["name"].Value, node.SelectSingleNode("descript").InnerText); XmlNodeList proNodes = node.SelectNodes("properties/property"); foreach (XmlNode n in proNodes) { prolist.Add(new XmlObjectProperty( n.Attributes["key"].Value, n.Attributes["name"].Value, n.InnerText)); } obj.Properties = prolist.ToArray(); return obj; }