/// <summary> /// Converts a UfDataNode structure into a very basic form HTML. /// </summary> /// <param name="node">Node</param> /// <param name="formatDescriber">Microformat format describer object</param> /// <returns>HTML string</returns> public string Convert(UfDataNode node, UfFormatDescriber formatDescriber) { string output = string.Empty; StringWriter stringWriter = new StringWriter(); UfElementDescriber elementDescriber = formatDescriber.BaseElement; using (XhtmlTextWriter writer = new XhtmlTextWriter(stringWriter)) { writer.WriteBeginTag("div"); writer.WriteAttribute("class", "microformats"); writer.Write(HtmlTextWriter.TagRightChar); foreach (UfDataNode child in node.Nodes) { writer.WriteLine(); AddNode(child, elementDescriber, writer); } writer.WriteEndTag("div"); writer.WriteLine(); } return stringWriter.ToString(); }
private void AddNode(UfDataNode node, UfElementDescriber elementDescriber, XhtmlTextWriter writer) { if (node.Name != string.Empty) { indentNum++; writer.Indent = indentNum; UfElementDescriber currentDescriber = elementDescriber; foreach (UfElementDescriber childElementDescriber in elementDescriber.Elements) { if (node.Name == childElementDescriber.Name || node.Name == childElementDescriber.CompoundName) { currentDescriber = childElementDescriber; } } if (currentDescriber.Attribute == "class") { writer.WriteBeginTag("div"); if (currentDescriber.CompoundName == "") writer.WriteAttribute("class", node.Name); else writer.WriteAttribute("class", node.Name + " " + currentDescriber.Name); if (!string.IsNullOrEmpty(node.ElementId)) writer.WriteAttribute("id", node.ElementId); writer.Write(HtmlTextWriter.TagRightChar); writer.WriteEncodedText(node.Value); foreach (UfDataNode child in node.Nodes) { writer.WriteLine(); AddNode(child, currentDescriber, writer); } if (node.Name != string.Empty) { writer.WriteEndTag("div"); writer.WriteLine(); } } if (currentDescriber.Attribute == "rel") { writer.WriteBeginTag("a"); writer.WriteAttribute("href", node.DescendantValue("link")); writer.WriteAttribute("rel", node.Name); writer.Write(HtmlTextWriter.TagRightChar); writer.WriteEncodedText(node.DescendantValue("text")); writer.WriteEndTag("a"); writer.WriteLine(); } indentNum--; writer.Indent = indentNum; } }
private void LoopItems(DictionaryItem item, XhtmlTextWriter writer) { switch (htmlTagName.ToLower().Trim()) { case "select": writer.WriteBeginTag("option"); writer.WriteAttribute("value", item.Key); if (IsSelected(item.Key)) { writer.WriteAttribute("selected", "selected"); } writer.Write(HtmlTextWriter.TagRightChar); int d = item.Depth; if (!String.IsNullOrEmpty(parentId)) { d -= parentId.Length / (provider == "category" ? Categories.Category.CATEGORY_LEVEL_LENGTH : DictionaryItem.KEY_LEVEL_LENGTH); } string text = BrandQQ.LeadLib.Utils.Util.RepeatString(identChar, (ushort)d); if (d > 0) { text += prefixChar; } writer.Write(text + item.Value); writer.WriteEndTag("option"); break; case "ul": writer.WriteBeginTag("li"); writer.WriteAttribute("id", "LI_" + this.ClientID + "_" + item.Key); writer.Write(HtmlTextWriter.TagRightChar); if (!String.IsNullOrEmpty(checkBoxOrRadio))//����ѡ�� { writer.WriteBeginTag("input"); writer.WriteAttribute("type", checkBoxOrRadio); writer.WriteAttribute("id", this.ClientID + "_" + item.Key); if (String.IsNullOrEmpty(htmlControlName)) { writer.WriteAttribute("name", this.ClientID); } else { writer.WriteAttribute("name", htmlControlName); } writer.WriteAttribute("value", item.Key); if (IsSelected(item.Key)) { writer.WriteAttribute("checked", "checked"); } writer.Write(HtmlTextWriter.SelfClosingTagEnd); writer.WriteBeginTag("label"); writer.WriteAttribute("for", this.ClientID + "_" + item.Key); writer.Write(HtmlTextWriter.TagRightChar); writer.Write(item.Value); writer.WriteEndTag("label"); } else { if (!String.IsNullOrEmpty(linkFormat)) { writer.Write(String.Format(linkFormat, item.Key, item.Value)); } else { writer.Write(item.Value); } } writer.WriteEndTag("li"); break; } if (item.Children.Count > 0 && htmlTagName.ToLower().Trim() == "ul") { writer.WriteFullBeginTag("ul"); } foreach (DictionaryItem subItem in item.Children) { LoopItems(subItem, writer); } if (item.Children.Count > 0 && htmlTagName.ToLower().Trim() == "ul") { writer.WriteEndTag("ul"); } }
protected override void Render(HtmlTextWriter writer) { ArrayList list=null; switch (provider.ToLower()) { case "industry": list = Dictionary.Industries; break; case "category": list = Dictionary.Categories; break; case "area": list = Dictionary.Areas; break; case "libclass": list = Dictionary.LibClasses; break; case "companynature": list = Dictionary.CompanyNatures; break; case "tags": foreach (string tag in Tag.GetTags()) { writer.WriteFullBeginTag("span"); writer.Write(tag); writer.WriteEndTag("span"); } return; } if (list == null) { return; } XhtmlTextWriter xWrite = new XhtmlTextWriter(writer); switch (htmlTagName.ToLower().Trim()) { case "select": xWrite.WriteBeginTag("select"); xWrite.WriteAttribute("id", this.ClientID); if (String.IsNullOrEmpty(htmlControlName)) { xWrite.WriteAttribute("name", this.ClientID); } else { xWrite.WriteAttribute("name", htmlControlName); } if (!String.IsNullOrEmpty(this.CssClass)) { xWrite.WriteAttribute("class", this.CssClass); } xWrite.Write(HtmlTextWriter.TagRightChar); if (!String.IsNullOrEmpty(defaultOptText)) { writer.WriteBeginTag("option"); writer.WriteAttribute("value", defaultOptValue); writer.Write(HtmlTextWriter.TagRightChar); writer.Write(defaultOptText); writer.WriteEndTag("option"); } foreach (DictionaryItem item in list) { LoopItems(item, xWrite); } xWrite.WriteEndTag("select"); break; case "ul": xWrite.WriteBeginTag("ul"); writer.WriteAttribute("id", "UL_" + this.ClientID); if (!String.IsNullOrEmpty(this.CssClass)) { xWrite.WriteAttribute("class", this.CssClass); } xWrite.Write(HtmlTextWriter.TagRightChar); foreach (DictionaryItem item in list) { LoopItems(item, xWrite); } xWrite.WriteEndTag("ul"); break; } }