public BookCardInfo Build(string content) { //reset mState = BookCardInfoBuilderState.TitleAuthor; mBookCardInfo = new BookCardInfo(); mContentAndIsbnTexts.Clear(); content = HREF_REGEX.Replace(content, ""); content = HtmlEntityCorrect.Encode(content); using (mReader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(content)))) { while (mReader.Read()) { switch (mReader.NodeType) { case XmlNodeType.Text: this.onText(HtmlEntityCorrect.Decode(mReader.Value)); break; case XmlNodeType.Element: this.onElement(HtmlEntityCorrect.Decode(mReader.Name)); break; } } } return(mBookCardInfo); }
private void onElementBr() { switch (mState) { case BookCardInfoBuilderState.ContentAndIsbn_Br: mState = BookCardInfoBuilderState.ContentAndIsbn_0; break; } }
private void onText(string text) { switch (mState) { case BookCardInfoBuilderState.TitleAuthor: getTitleAndAuthor(text); mState = BookCardInfoBuilderState.Publisher; break; case BookCardInfoBuilderState.ContentAndIsbn_0: pushText(text); break; case BookCardInfoBuilderState.ContentAndIsbn_1: pushText(text); break; } }
private void onElementA() { switch (mState) { case BookCardInfoBuilderState.Publisher: mBookCardInfo.Publisher = HtmlEntityCorrect.Decode(mReader.ReadString()); mState = BookCardInfoBuilderState.ContentAndIsbn_Br; break; //遇到第二个a元素则内容和ISBN结束 case BookCardInfoBuilderState.ContentAndIsbn_0: mState = BookCardInfoBuilderState.ContentAndIsbn_1; break; case BookCardInfoBuilderState.ContentAndIsbn_1: getContentAndIsbn(); mState = BookCardInfoBuilderState.Other; break; } }
public BookCardInfo Build(string content) { //reset mState = BookCardInfoBuilderState.TitleAuthor; mBookCardInfo = new BookCardInfo(); mContentAndIsbnTexts.Clear(); content = HREF_REGEX.Replace(content, ""); content = HtmlEntityCorrect.Encode(content); using (mReader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(content)))) { while (mReader.Read()) { switch (mReader.NodeType) { case XmlNodeType.Text: this.onText(HtmlEntityCorrect.Decode(mReader.Value)); break; case XmlNodeType.Element: this.onElement(HtmlEntityCorrect.Decode(mReader.Name)); break; } } } return mBookCardInfo; }