Пример #1
0
            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);
            }
Пример #2
0
 private void onElementBr()
 {
     switch (mState)
     {
     case BookCardInfoBuilderState.ContentAndIsbn_Br:
         mState = BookCardInfoBuilderState.ContentAndIsbn_0;
         break;
     }
 }
Пример #3
0
            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;
                }
            }
Пример #4
0
            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;
                }
            }
Пример #5
0
            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;
            }
Пример #6
0
 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;
     }
 }
Пример #7
0
 private void onElementBr()
 {
     switch (mState)
     {
         case BookCardInfoBuilderState.ContentAndIsbn_Br:
             mState = BookCardInfoBuilderState.ContentAndIsbn_0;
             break;
     }
 }
Пример #8
0
 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;
     }
 }