Ejemplo n.º 1
0
 internal 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.IsKnown)
         {
             // unknown tag, remember this is self closing for output. see above.
             tag.SetSelfClosing();
         }
     }
     else
     {
         stack.AddLast(el);
     }
     return el;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// If the stack contains an element with this tag's name, pop up the stack to remove the first occurrence.
 /// </summary>
 /// <remarks>
 /// If not found, skips.
 /// </remarks>
 /// <param name="endTag"></param>
 private void PopStackToClose(Token.EndTag endTag)
 {
     string elName = endTag.Name();
     Element firstFound = null;
     var it = stack.GetDescendingEnumerator();
     while (it.MoveNext())
     {
         Element next = it.Current;
         if (next.NodeName.Equals(elName))
         {
             firstFound = next;
             break;
         }
     }
     if (firstFound == null)
     {
         // not found, skip
         return;
     }
     it = stack.GetDescendingEnumerator();
     while (it.MoveNext())
     {
         Element next = it.Current;
         if (next == firstFound)
         {
             it.Remove();
             break;
         }
         else
         {
             it.Remove();
         }
     }
 }
Ejemplo n.º 3
0
 internal Element InsertEmpty(Token.StartTag startTag)
 {
     Tag tag = Tag.ValueOf(startTag.Name());
     Element el = new Element(tag, baseUri, startTag.attributes);
     InsertNode(el);
     if (startTag.IsSelfClosing())
     {
         if (tag.IsKnown)
         {
             if (tag.IsSelfClosing)
             {
                 tokeniser.AcknowledgeSelfClosingFlag();
             }
         }
         else
         {
             // if not acked, promulagates error
             // unknown tag, remember this is self closing for output
             tag.SetSelfClosing();
             tokeniser.AcknowledgeSelfClosingFlag();
         }
     }
     // not an distinct error
     return el;
 }
Ejemplo n.º 4
0
 internal FormElement InsertForm(Token.StartTag startTag, bool onStack)
 {
     Tag tag = Tag.ValueOf(startTag.Name());
     FormElement el = new FormElement(tag, baseUri, startTag.attributes);
     SetFormElement(el);
     InsertNode(el);
     if (onStack)
     {
         stack.AddLast(el);
     }
     return el;
 }
Ejemplo n.º 5
0
 internal Element Insert(Token.StartTag startTag)
 {
     // handle empty unknown tags
     // when the spec expects an empty tag, will directly hit insertEmpty, so won't generate this fake end tag.
     if (startTag.IsSelfClosing())
     {
         Element el = InsertEmpty(startTag);
         stack.AddLast(el);
         tokeniser.Transition(TokeniserState.Data);
         // handles <script />, otherwise needs breakout steps from script data
         tokeniser.Emit(new Token.EndTag(el.TagName));
         // ensure we get out of whatever state we are in. emitted for yielded processing
         return el;
     }
     Tag tag = Tag.ValueOf(startTag.Name());
     Element el_1 = new Element(tag, baseUri, startTag.attributes);
     Insert(el_1);
     return el_1;
 }