Beispiel #1
0
 /// <summary>
 /// Creates a new HTML tag that encloses another HTML tag
 /// </summary>
 /// <param name="tagName">Name of this tag</param>
 /// <param name="enclosedTag">Tag that will enclodes by this tag. Means: <THISTAG><ENCLOSEDTAG></ENCLOSEDTAG></THISTAG>  </param>
 public WeakHTMLTag(string tagName, WeakHTMLTag enclosedTag)
     : this(tagName, WeakHTMLContentType.HTML, enclosedTag.ToString())
 {
     if (enclosedTag == null)
     {
         throw new ArgumentNullException();
     }
 }
Beispiel #2
0
        /// <summary>
        /// Clones an existing HTML tag
        /// </summary>
        /// <param name="cloneSource">The source WeakHTMLTag that should be cloned</param>
        public WeakHTMLTag(WeakHTMLTag cloneSource)
        {
            if (cloneSource == null)
            {
                throw new ArgumentNullException();
            }

            XElement clone = XElement.Parse(cloneSource.BaseXElement.ToString());

            _xelem = clone; //Value is already set to GUID_REPLACE

            this.HTML       = cloneSource.HTML;
            this.Attributes = new WeakHTMLAttributes(_xelem);
        }
Beispiel #3
0
        public string this[string name]
        {
            get
            {
                if (_element.Attribute(name) != null)
                {
                    return(_element.Attribute(name).Value);
                }
                else
                {
                    return(string.Empty);
                }
            }

            set
            {
                string val = WeakHTMLTag.HTMLEncode(value);
                _element.SetAttributeValue(name, val);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates a clone of a existing WeakHTMLTag and encloses another WeakHTMLTag into it.
        /// </summary>
        /// <param name="outerTag">The WeakHTMLTag that used as the outer tag</param>
        /// <param name="enclosedTag">The WeakHTMLTag used as the inner (enclosed) tag</param>
        public WeakHTMLTag(WeakHTMLTag outerTag, WeakHTMLTag enclosedTag)
            : this(outerTag)
        {
            if (enclosedTag == null)
            {
                throw new ArgumentNullException();
            }

            //This element is now correctly set to the data in OuterTag
            //If this HTML tag does not have any value, we can use directly EnclosedTag as data
            if (string.IsNullOrWhiteSpace(this.HTML))
            {
                this.HTML = enclosedTag.ToString();
            }
            else
            {
                //This HTML tag has a value set, so combine those two
                this.HTML += enclosedTag.ToString();
            }
        }
Beispiel #5
0
        /// <summary>
        /// Concats several WeakHTMLTags into one. The first pameter is the outer tag, second tag is enclosed in first tag, third tag is enclosed in second tag and so on.
        /// </summary>
        /// <param name="tags"></param>
        /// <returns></returns>
        public static WeakHTMLTag Concat(params WeakHTMLTag[] tags)
        {
            //If we do not have any tag, return an exception
            if (tags.Length == 0)
            {
                throw new ArgumentException("At least one WeakHTMLTag to concat is required");
            }
            else
            {
                //If we only get one item, return it
                if (tags.Length == 1)
                {
                    return(tags[0]);
                }
                else
                {
                    WeakHTMLTag current = null;

                    //Loop all objects, starting with the last
                    for (int i = tags.Length - 1; i >= 0; i--)
                    {
                        if (current != null)
                        {
                            WeakHTMLTag temp = new WeakHTMLTag(tags[i], current);
                            current = temp;
                        }
                        else
                        {
                            //No current is present so far, use this element
                            current = tags[i];
                        }
                    }

                    return(current);
                }
            }
        }