示例#1
0
        public HtmlNode ParseElement(List <HtmlToken> tokens, ref int index)
        {
            HtmlElement elem = new HtmlElement();

            elem.parentNode = current;
            current         = elem;

            if (current is HtmlDocument)
            {
                elem.ownerDocument = current as HtmlDocument;
            }
            else
            {
                elem.ownerDocument = elem.parentNode.ownerDocument;
            }

            ReadType(tokens, index, TokenType.HtmlElement).OrThrow("Expect Element");
            HtmlToken elemName = tokens[index];

            elem.name = elemName;

            Move(tokens, ref index);
            while (ReadType(tokens, index, TokenType.HtmlAttributeName))
            {
                HtmlAttribute attr = (HtmlAttribute)ParseAttribute(tokens, ref index);
                elem.attrs.Add(attr.attrName, attr.attrValue);
                Move(tokens, ref index);
            }
            if (ReadType(tokens, index, TokenType.HtmlSlash))
            {
                Move(tokens, ref index);
                ReadType(tokens, index, TokenType.HtmlElementEnd).OrThrow("Expect >");
            }
            else if (ReadType(tokens, index, TokenType.HtmlElementEnd))
            {
                Move(tokens, ref index);
                ParseNodeList(tokens, ref index);
                ReadType(tokens, index, TokenType.HtmlElementBegin).OrThrow("Expect <");
                Move(tokens, ref index);
                ReadType(tokens, index, TokenType.HtmlSlash).OrThrow("Expect /");
                Move(tokens, ref index);
                ReadType(tokens, index, TokenType.HtmlElementClosed).OrThrow("Expect Element Close");
                (elemName.value == tokens[index].value).OrThrow("Element Name needs match");
            }

            current = current.parentNode;
            return(elem);
        }
示例#2
0
 public HtmlElement(HtmlToken _token)
     : base(_token)
 {
 }
示例#3
0
 public HtmlDocument(HtmlToken _token)
     : base(_token)
 {
 }
示例#4
0
 public HtmlNode(HtmlToken _token)
 {
     this.name = _token;
 }
示例#5
0
 public HtmlText(HtmlElement _elem, HtmlToken text)
     : base(text)
 {
     this.elem = _elem;
     this.text = text;
 }