/// <summary> /// Add an XHTMLElement to XHTMLTree /// </summary> /// <param name="element">Element to add</param> private void AddElement(XHTMLElement element) { //If no root element, create new root if (Root == null) { if (element.GetTagState()) { Root = element; } else { XHTMLElement newRoot = new XHTMLElement("html", null, true); Root = newRoot; Current = Root; newRoot.AddChild(element); } } else { //Add element as child of current element Current.AddChild(element); } if (element.GetTagState()) { Current = element; Depth++; } }
/// <summary> /// Visit XHTMLElement and write it to stream /// </summary> /// <param name="element">Element to visit</param> public void Visit(XHTMLElement element) { if (element.GetTag() == "cdata") { //CData need different handling WriteCData(element); } else if (element.GetTag() == "comment") { //Write comment WriteComment(element); } else { //Normal XHTML tag handling XhtmlWriter.BeginRender(); //Check if element is tag, if not write tag, otherwise handle as XHTML tag if (!element.GetTagState()) { XhtmlWriter.BeginRender(); //Get escape chars out of this tag CharIterator charIterator = new CharIterator(); String tag = charIterator.ParseText(element.GetTag()); XhtmlWriter.Write(tag); XhtmlWriter.EndRender(); XhtmlWriter.Flush(); return; } XhtmlWriter.WriteBeginTag(element.GetTag()); foreach (KeyValuePair <String, String> pair in element.GetAttributes()) { XhtmlWriter.WriteAttribute(pair.Key, pair.Value, false); } if (IsEmptyElement(element)) { //Nothing inside element, so write tag end XhtmlWriter.Write(XhtmlTextWriter.SelfClosingTagEnd); } else if (IsXHTMLTag(element.GetTag())) { //Write tag opening closing XhtmlWriter.Write(XhtmlTextWriter.TagRightChar); //Write content XhtmlWriter.Write(element.GetContent()); //Visit children foreach (XHTMLElement child in element.GetChildren()) { Visit(child); } //Write closing tag XhtmlWriter.WriteEndTag(element.GetTag()); XhtmlWriter.Flush(); } else { //Just write it XhtmlWriter.Write(element.GetTag()); XhtmlWriter.EndRender(); XhtmlWriter.Flush(); } } }
/// <summary> /// Visit XHTMLElement and write it to stream /// </summary> /// <param name="element">Element to visit</param> public void Visit(XHTMLElement element) { if (element.GetTag() == "cdata") { //CData need different handling WriteCData(element); } else if (element.GetTag() == "comment") { //Write comment WriteComment(element); } else { //Normal XHTML tag handling XhtmlWriter.BeginRender(); //Check if element is tag, if not write tag, otherwise handle as XHTML tag if (!element.GetTagState()) { XhtmlWriter.BeginRender(); //Get escape chars out of this tag CharIterator charIterator = new CharIterator(); String tag = charIterator.ParseText(element.GetTag()); XhtmlWriter.Write(tag); XhtmlWriter.EndRender(); XhtmlWriter.Flush(); return; } XhtmlWriter.WriteBeginTag(element.GetTag()); foreach (KeyValuePair<String, String> pair in element.GetAttributes()) { XhtmlWriter.WriteAttribute(pair.Key, pair.Value, false); } if (IsEmptyElement(element)) { //Nothing inside element, so write tag end XhtmlWriter.Write(XhtmlTextWriter.SelfClosingTagEnd); } else if (IsXHTMLTag(element.GetTag())) { //Write tag opening closing XhtmlWriter.Write(XhtmlTextWriter.TagRightChar); //Write content XhtmlWriter.Write(element.GetContent()); //Visit children foreach (XHTMLElement child in element.GetChildren()) { Visit(child); } //Write closing tag XhtmlWriter.WriteEndTag(element.GetTag()); XhtmlWriter.Flush(); } else { //Just write it XhtmlWriter.Write(element.GetTag()); XhtmlWriter.EndRender(); XhtmlWriter.Flush(); } } }