private XmlElement GetElementGroupInfoTable(HtmlElementGroup e){ XmlElement result = Html.Create("table"); result.SetAttribute("summary", ElementGroupInfoTableSummary); 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, parents, contents); tbody.AppendChild(tbodyTr); return result; }
// データの取得 // データのロード public void AddData(HtmlElementGroup heg){ Object[] data = new Object[]{null, heg.Id, heg.Name, heg}; DataRow row = this.NewRow(); row.ItemArray = data; this.Rows.Add(row); }
/// <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);}); }
// 要素グループの子要素を解析して配列に格納します。 // 排除要素以外の要素に対しては、親として関連づけます。 private void SetChildren(HtmlElementGroup heg){ List<HtmlItem> contents = new List<HtmlItem>(); //要素を探す foreach(XmlElement e in heg.XmlElement.ChildNodes){ if(e == null) continue; string s = e.GetInnerText(); HtmlItem item = null; switch(e.LocalName){ case ElementsElementName: item = GetElement(s); break; case GroupsElementName: item = GetElementGroup(s); if(item == null) item = GetElementGroupByName(s); break; case DatasElementName: item = GetDataByName(s); break; } if(item == null) continue; contents.Add(item); item.AddParent(heg); } heg.Content = contents.ToArray(); }
// Row[] を HtmlElementGroup[] に変換します。 private HtmlElementGroup[] DataRowsToHtmlElementGroup(DataRow[] rows){ HtmlElementGroup[] result = new HtmlElementGroup[rows.Length]; for(int i = 0; i < rows.Length; i++){ result[i] = GetHtmlElementGroup(rows[i]); } return result; }