// ====================================================================
        //
        //  PRIVATE/PROTECTED METHODS
        //
        // ====================================================================
        private void CheckTag()
        {
            if (TagName.EndsWith("/"))
            {
                TagName = TagName.Substring(0, TagName.Length - 1);
            }
            TagNameNS = TagName;

            ElementInfo = HtmlElementInfo.GetElementInfo(TagNameNS);

            int pos = TagName.IndexOf(':');

            if (pos != -1)
            {
                Namespace = TagName.Substring(0, pos);
                TagName   = TagName.Substring(pos + 1);
            }
            if (ElementInfo == null)
            {
                if (Namespace == null)
                {
                    AddWarning("Unknown tag: " + TagName);
                }
            }
            else
            {
                if (Parent != null)
                {
                    if (!ElementInfo.IsValidParent(Parent.TagName))
                    {
                        AddWarning("Invalid parent for " + TagName + " (parent: " + Parent.TagName + ")");
                    }
                }
            }
        }
示例#2
0
        public HtmlTag(string tag)
            : this()
        {
            tag = tag.Substring(1, tag.Length - 2);

            var spaceIndex = tag.IndexOf(" ");

            //Extract tag name
            if (spaceIndex < 0)
            {
                TagName = tag;
            }
            else
            {
                TagName = tag.Substring(0, spaceIndex);
            }

            //Check if is end tag
            if (TagName.StartsWith("/"))
            {
                IsClosing = true;
                TagName   = TagName.Substring(1);
            }

            TagName = TagName.ToLower();

            //Extract attributes
            var atts = Parser.Match(Parser.HmlTagAttributes, tag);

            foreach (Match att in atts)
            {
                //Extract attribute and value
                var chunks = att.Value.Split('=');

                if (chunks.Length == 1)
                {
                    if (!Attributes.ContainsKey(chunks[0]))
                    {
                        Attributes.Add(chunks[0].ToLower(), string.Empty);
                    }
                }
                else if (chunks.Length == 2)
                {
                    var attname  = chunks[0].Trim();
                    var attvalue = chunks[1].Trim();

                    if (attvalue.StartsWith("\"") && attvalue.EndsWith("\"") && attvalue.Length > 2)
                    {
                        attvalue = attvalue.Substring(1, attvalue.Length - 2);
                    }

                    if (!Attributes.ContainsKey(attname))
                    {
                        Attributes.Add(attname, attvalue);
                    }
                }
            }
        }
示例#3
0
        public FormatTag(string data)
        {
            var tagEnd = data.IndexOf(">");

            Tag     = tagEnd > 0 ? data.Substring(0, tagEnd + 1) : "";
            TagName = Tag.Trim(new[] { '<', '>' }).ToLower();
            if (Tag.Length > 4 && char.IsNumber(data[Tag.Length - 3]) && char.IsNumber(data[Tag.Length - 2]))
            {
                Height  = Convert.ToInt32(Tag[Tag.Length - 3].ToString());
                Width   = Convert.ToInt32(Tag[Tag.Length - 2].ToString());
                TagName = TagName.Substring(0, TagName.Length - 2);
            }
        }