Ejemplo n.º 1
0
            public BookInfo Build(Stream content)
            {
                //reset
                mContentStream = content;
                mBookInfo      = new BookInfo();

                using (var reader = new StreamReader(mContentStream))
                {
                    var bookInfoStr = reader.ReadToEnd();
                    var match       = BookCardInfoRegex.Match(bookInfoStr);
                    if (match.Success)
                    {
                        var bookCardInfoStr = match.Groups[0].Value;
                        mBookInfo.CardInfo = BookCardInfo.Build(bookCardInfoStr);
                    }
                    var deptStr = bookInfoStr.Substring(bookInfoStr.IndexOf("藏书情况"));
                    match = DeptInfoRegex.Match(bookInfoStr);
                    if (match.Success)
                    {
                        var deptInfoStr = match.Groups[0].Value;
                        mBookInfo.DeptInfos = DeptInfo.Build(deptInfoStr);
                    }
                    return(mBookInfo);
                }
            }
Ejemplo n.º 2
0
            public List <DeptInfo> Build(string content)
            {
                //reset
                mDeptInfos = new List <DeptInfo>();

                content = HtmlEntityCorrect.Encode(content);

                using (mReader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(content))))
                {
                    DeptInfo deptInfo = null;

                    while (mReader.Read())
                    {
                        if (mReader.NodeType == XmlNodeType.Element)
                        {
                            if (mReader.Name == "tr")
                            {
                                deptInfo = new DeptInfo();
                                mDeptInfos.Add(deptInfo);
                                mState = DeptInfoBuilderState.DeptPlace;
                            }
                            else if (mReader.Name == "a")
                            {
                                deptInfo.DeptPlace = HtmlEntityCorrect.Decode(mReader.ReadString().Trim());
                                mState             = DeptInfoBuilderState.Index;
                            }
                            else if (mReader.Name == "td")
                            {
                                switch (mState)
                                {
                                case DeptInfoBuilderState.Index:
                                    deptInfo.Index = HtmlEntityCorrect.Decode(mReader.ReadString()).Trim();
                                    mState         = DeptInfoBuilderState.Register;
                                    break;

                                case DeptInfoBuilderState.Register:
                                    deptInfo.Register = HtmlEntityCorrect.Decode(mReader.ReadString()).Trim();
                                    mState            = DeptInfoBuilderState.Volume;
                                    break;

                                case DeptInfoBuilderState.Volume:
                                    deptInfo.Volume = HtmlEntityCorrect.Decode(mReader.ReadString()).Trim();
                                    mState          = DeptInfoBuilderState.Year;
                                    break;

                                case DeptInfoBuilderState.Year:
                                    deptInfo.Year = HtmlEntityCorrect.Decode(mReader.ReadString()).Trim();
                                    mState        = DeptInfoBuilderState.Status;
                                    break;

                                case DeptInfoBuilderState.Status:
                                    deptInfo.Status = HtmlEntityCorrect.Decode(mReader.ReadString()).Trim();
                                    mState          = DeptInfoBuilderState.Type;
                                    break;

                                case DeptInfoBuilderState.Type:
                                    deptInfo.Type = HtmlEntityCorrect.Decode(mReader.ReadString()).Trim();
                                    mState        = DeptInfoBuilderState.Other;
                                    break;

                                default:
                                    break;
                                }
                            }
                        }
                    }
                }
                return(mDeptInfos);
            }
Ejemplo n.º 3
0
            public List<DeptInfo> Build(string content)
            {
                //reset
                mDeptInfos = new List<DeptInfo>();

                content = HtmlEntityCorrect.Encode(content);

                using (mReader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(content))))
                {
                    DeptInfo deptInfo = null;

                    while (mReader.Read())
                    {
                        if (mReader.NodeType == XmlNodeType.Element)
                        {
                            if (mReader.Name == "tr")
                            {
                                deptInfo = new DeptInfo();
                                mDeptInfos.Add(deptInfo);
                                mState = DeptInfoBuilderState.DeptPlace;
                            }
                            else if (mReader.Name == "a")
                            {
                                deptInfo.DeptPlace = HtmlEntityCorrect.Decode(mReader.ReadString().Trim());
                                mState = DeptInfoBuilderState.Index;
                            }
                            else if (mReader.Name == "td")
                            {
                                switch (mState)
                                {
                                    case DeptInfoBuilderState.Index:
                                        deptInfo.Index = HtmlEntityCorrect.Decode(mReader.ReadString()).Trim();
                                        mState = DeptInfoBuilderState.Register;
                                        break;
                                    case DeptInfoBuilderState.Register:
                                        deptInfo.Register = HtmlEntityCorrect.Decode(mReader.ReadString()).Trim();
                                        mState = DeptInfoBuilderState.Volume;
                                        break;
                                    case DeptInfoBuilderState.Volume:
                                        deptInfo.Volume = HtmlEntityCorrect.Decode(mReader.ReadString()).Trim();
                                        mState = DeptInfoBuilderState.Year;
                                        break;
                                    case DeptInfoBuilderState.Year:
                                        deptInfo.Year = HtmlEntityCorrect.Decode(mReader.ReadString()).Trim();
                                        mState = DeptInfoBuilderState.Status;
                                        break;
                                    case DeptInfoBuilderState.Status:
                                        deptInfo.Status = HtmlEntityCorrect.Decode(mReader.ReadString()).Trim();
                                        mState = DeptInfoBuilderState.Type;
                                        break;
                                    case DeptInfoBuilderState.Type:
                                        deptInfo.Type = HtmlEntityCorrect.Decode(mReader.ReadString()).Trim();
                                        mState = DeptInfoBuilderState.Other;
                                        break;
                                    default:
                                        break;
                                }
                            }
                        }
                    }
                }
                return mDeptInfos;
            }