Example #1
0
 Element Insert(Token.StartTag startTag)
 {
     Tag tag = Tag.ValueOf(startTag.Name());
     // todo: wonder if for xml parsing, should treat all tags as unknown? because it's not html.
     Element el = new Element(tag, _baseUri, startTag.Attributes);
     InsertNode(el);
     if (startTag.IsSelfClosing)
     {
         _tokeniser.AcknowledgeSelfClosingFlag();
         if (!tag.IsKnownTag()) // unknown tag, remember this is self closing for output. see above.
             tag.SetSelfClosing();
     }
     else
     {
         _stack.AddLast(el);
     }
     return el;
 }
Example #2
0
        /**
         * If the stack contains an element with this tag's name, pop up the stack to remove the first occurrence. If not
         * found, skips.
         *
         * @param endTag
         */
        private void PopStackToClose(Token.EndTag endTag)
        {
            string elName = endTag.Name();
            Element firstFound = null;

            IEnumerator<Element> it = _stack.GetDescendingEnumerator();
            while (it.MoveNext())
            {
                Element next = it.Current;
                if (next.NodeName.Equals(elName))
                {
                    firstFound = next;
                    break;
                }
            }
            if (firstFound == null)
            {
                return; // not found, skip
            }

            it = _stack.GetDescendingEnumerator();
            List<Element> remove = new List<Element>();
            while (it.MoveNext())
            {
                Element next = it.Current;
                if (next == firstFound)
                {
                    remove.Add(next);
                    break;
                }
                else
                {
                    remove.Add(next);
                }
            }
            foreach (Element item in remove)
            {
                _stack.Remove(item);
            }
        }
Example #3
0
 public Element InsertEmpty(Token.StartTag startTag)
 {
     Tag tag = Tag.ValueOf(startTag.Name());
     Element el = new Element(tag, _baseUri, startTag.Attributes);
     InsertNode(el);
     if (startTag.IsSelfClosing)
     {
         _tokeniser.AcknowledgeSelfClosingFlag();
         if (!tag.IsKnownTag()) // unknown tag, remember this is self closing for output
         {
             tag.SetSelfClosing();
         }
     }
     return el;
 }
Example #4
0
        public Element Insert(Token.StartTag startTag)
        {
            // handle empty unknown tags
            // when the spec expects an empty tag, will directly hit insertEmpty, so won't generate fake end tag.
            if (startTag.IsSelfClosing && !Tag.IsKnownTag(startTag.Name()))
            {
                Element el = InsertEmpty(startTag);
                Process(new Token.EndTag(el.TagName())); // ensure we get out of whatever state we are in
                return el;
            }

            Element element = new Element(Tag.ValueOf(startTag.Name()), _baseUri, startTag.Attributes);
            Insert(element);
            return element;
        }