private XmlElement GetElementInfoTable(HtmlElement e){ XmlElement result = Html.Create("table"); result.SetAttribute("summary", ElementInfoTableSummary); XmlElement thead = Html.Create("thead"); result.AppendChild(thead); XmlElement theadTr = Html.HeadTr(null, "要素名", "バージョン", "開始タグ", "終了タグ", "分類/親", "中身"); thead.AppendChild(theadTr); XmlElement tbody = Html.Create("tbody"); result.AppendChild(tbody); XmlNode parents = GetHtmlItemList(e.Parents, ", "); XmlNode contents = GetHtmlItemList(e.Content); XmlElement tbodyTr = Html.Tr(null, 0, e.Name, e.GetVersion(), e.GetOmitStartTag(), e.GetOmitEndTag(), parents, contents); tbody.AppendChild(tbodyTr); return result; }
// データのロード public void AddData(HtmlElement e){ Object[] data = new Object[]{null, e.Id, e.Name, e}; DataRow row = this.NewRow(); row.ItemArray = data; this.Rows.Add(row); }
// 要素の子要素を解析して配列に格納します。 // 排除要素以外の要素に対しては、親として関連づけます。 private void SetAttribute(HtmlElement he){ // 属性を探す List<HtmlAttribute> attrs = new List<HtmlAttribute>(); foreach(XmlElement e in he.XmlElement.GetElementsByTagName(AttributeElementName)){ if(e == null) continue; string s = e.GetInnerText(); HtmlAttribute ha = GetAttribute(s, he); attrs.Add(ha); ha.AddParent(he); } he.Attributes = attrs.ToArray(); // 属性を探す List<HtmlAttributeGroup> attrGroups = new List<HtmlAttributeGroup>(); foreach(XmlElement e in he.XmlElement.GetElementsByTagName(AttributesElementName)){ if(e == null) continue; string s = e.GetInnerText(); HtmlAttributeGroup hag = GetAttributeGroupByName(s); attrGroups.Add(hag); hag.AddParent(he); } he.AttributeGroups = attrGroups.ToArray(); }
// 要素の子要素を解析して配列に格納します。 // 排除要素以外の要素に対しては、親として関連づけます。 private void SetChildren(HtmlElement he){ string contentStr = he.XmlElement.GetInnerText(ContentElementName); if(contentStr == EmptyContent) he.IsEmptyElement = true; int exIndex = contentStr.IndexOf(ContentExcludeSymbol); string include; string exclude; if(exIndex < 0){ include = contentStr; exclude = null; } else { include = contentStr.Substring(0, exIndex); exclude = contentStr.Substring(exIndex); } List<HtmlItem> includeItems = SearchChildren(include); // include な要素たちに対しては親として関連づける includeItems.ForEach(item=>{item.AddParent(he);}); includeItems.AddRange(SearchChildren(exclude)); he.Content = includeItems.ToArray(); }
/// <summary> /// 指定された XML ファイルからデータをロードします。 /// この処理はスレッドセーフではありません。 /// </summary> public void Load(){ XmlNodeList elems = Document.DocumentElement[ElementsRefName].GetElementsByTagName(ElementElementName); XmlNodeList elemGroups = Document.DocumentElement[ElementsRefName].GetElementsByTagName(ElementGroupElementName); XmlNodeList attrs = Document.DocumentElement[AttributesRefName].GetElementsByTagName(AttributeElementName); XmlNodeList attrGroups = Document.DocumentElement[AttributesRefName].GetElementsByTagName(AttributeGroupElementName); XmlNodeList datas = Document.DocumentElement[DataRefName].GetElementsByTagName(DataFormatElementName); HtmlElement[] he = new HtmlElement[elems.Count]; for(int i=0; i < elems.Count; i++){he[i] = new HtmlElement(elems[i] as XmlElement);} HtmlElementGroup[] heg = new HtmlElementGroup[elemGroups.Count]; for(int i=0; i < elemGroups.Count; i++){heg[i] = new HtmlElementGroup(elemGroups[i] as XmlElement);} HtmlAttribute[] ha = new HtmlAttribute[attrs.Count]; for(int i=0; i < attrs.Count; i++){ha[i] = new HtmlAttribute(attrs[i] as XmlElement);} HtmlAttributeGroup[] hag = new HtmlAttributeGroup[attrGroups.Count]; for(int i=0; i < attrGroups.Count; i++){hag[i] = new HtmlAttributeGroup(attrGroups[i] as XmlElement);} HtmlData[] hd = new HtmlData[datas.Count]; for(int i=0; i < datas.Count; i++){hd[i] = new HtmlData(datas[i] as XmlElement);} ElementTable.MinimumCapacity = he.Length; Array.ForEach(he, item=>{ElementTable.AddData(item);}); ElementGroupTable.MinimumCapacity = heg.Length; Array.ForEach(heg, item=>{ElementGroupTable.AddData(item);}); AttributeTable.MinimumCapacity = ha.Length; Array.ForEach(ha, item=>{AttributeTable.AddData(item);}); AttributeGroupTable.MinimumCapacity = hag.Length; Array.ForEach(hag, item=>{AttributeGroupTable.AddData(item);}); DataTable.MinimumCapacity = hd.Length; Array.ForEach(hd, item=>{DataTable.AddData(item);}); // 属性や親子関係を取得 Array.ForEach(he, item=>{SetChildren(item);SetAttribute(item);}); Array.ForEach(heg, item=>{SetChildren(item);}); Array.ForEach(ha, item=>{SetChildren(item);}); Array.ForEach(hag, item=>{SetChildren(item);}); }
/// <summary> /// 指定された要素の指定された名前の属性を取得します。 /// </summary> public HtmlAttribute GetAttribute(string id, HtmlElement he){ return GetAttribute(id, he.Id); }
// Row[] を HtmlElement[] に変換します。 private HtmlElement[] DataRowsToHtmlElement(DataRow[] rows){ HtmlElement[] result = new HtmlElement[rows.Length]; for(int i = 0; i < rows.Length; i++){ result[i] = GetHtmlElement(rows[i]); } return result; }