コード例 #1
0
ファイル: ProcessP.cs プロジェクト: VadimDang/Process_ebook
        public void Process()
        {
            if (_sequence == int.MaxValue)
            {
                int t = int.MaxValue;
                foreach (XmlNode childNode in _root.ChildNodes)
                {
                    if (childNode.Attributes == null || childNode.Attributes["rel"] == null)
                        continue;

                    t = int.Parse(childNode.Attributes["rel"].Value);
                    if (t < _sequence)
                        _sequence = t;

                }
            }

            int tempSequence = _sequence;
            List<XmlNode> reserveNodeList = new List<XmlNode>();
            List<XmlNode> removeNodeList1 = new List<XmlNode>();
            foreach (XmlNode childNode in _root.ChildNodes)
            {
                int t = int.MaxValue;

                if (childNode.Name == "br")
                {
                    continue;
                }

                if (childNode.Name != "span")
                {
                    ProcessDiv pDiv = new ProcessDiv(childNode);
                    pDiv.Sequence = _sequence;
                    pDiv.Process();
                    _sequence = pDiv.Sequence;
                    continue;
                }

                if (childNode.Attributes["rel"] != null)
                    t = int.Parse(childNode.Attributes["rel"].Value);
                if (t < tempSequence)
                    tempSequence = t;

                if (childNode.Attributes == null || childNode.Attributes["rel"] == null)
                {

                }
                else
                {
                    t = int.Parse(childNode.Attributes["rel"].Value);
                    if (t == _sequence)
                    {
                        _sequence++;
                    }
                    if (t - _sequence > _root.ChildNodes.Count || t < _sequence - 2)
                        removeNodeList1.Add(childNode);

                    List<XmlNode> removeNodeList2 = new List<XmlNode>();
                    foreach (XmlNode cNode in childNode.ChildNodes)
                    {
                        if (cNode.Attributes == null || cNode.Attributes["rel"] == null)
                            continue;

                        if (cNode.Name == "a" || cNode.Name == "i" || cNode.Name == "b")
                        {
                            ProcessDiv pDiv = new ProcessDiv(cNode);
                            pDiv.Sequence = _sequence;
                            pDiv.Process();
                            _sequence = pDiv.Sequence;
                            continue;
                        }

                        t = int.Parse(cNode.Attributes["rel"].Value);
                        if (t == _sequence)
                        {
                            _sequence++;
                        }

                        if (t - _sequence > childNode.ChildNodes.Count || t < _sequence - 2)
                            removeNodeList2.Add(cNode);

                        List<XmlNode> removeNodeList3 = new List<XmlNode>();
                        foreach (XmlNode ccNode in cNode.ChildNodes)
                        {
                            if (ccNode.Attributes == null || ccNode.Attributes["rel"] == null)
                                continue;

                            if (ccNode.Name == "a" || ccNode.Name == "i" || ccNode.Name == "b")
                            {
                                ProcessDiv pDiv = new ProcessDiv(ccNode);
                                pDiv.Sequence = _sequence;
                                pDiv.Process();
                                _sequence = pDiv.Sequence;
                                continue;
                            }

                            t = int.Parse(ccNode.Attributes["rel"].Value);
                            if (t == _sequence)
                            {
                                _sequence++;
                            }

                            if (t - _sequence > cNode.ChildNodes.Count || t < _sequence - 2)
                                removeNodeList3.Add(ccNode);
                        }
                        foreach (XmlNode rNode in removeNodeList3)
                        {
                            cNode.RemoveChild(rNode);
                        }

                    }

                    foreach (XmlNode rNode in removeNodeList2)
                    {
                        childNode.RemoveChild(rNode);
                    }
                }

            }

            foreach (XmlNode rNode in removeNodeList1)
            {
                _root.RemoveChild(rNode);
            }

            //Format node
            //foreach (XmlNode childNode in _root.ChildNodes)
            //{
            //    Utility.FormatStringNode(childNode);
            //    foreach (XmlNode cNode in childNode.ChildNodes)
            //    {
            //        Utility.FormatStringNode(cNode);
            //        foreach (XmlNode ccNode in cNode.ChildNodes)
            //        {
            //            Utility.FormatStringNode(ccNode);
            //        }
            //    }
            //}
        }
コード例 #2
0
ファイル: ProcessDiv.cs プロジェクト: VadimDang/Process_ebook
        public void Process()
        {
            if (_sequence == int.MaxValue)
            {
                int t = int.MaxValue;
                foreach (XmlNode childNode in _root.ChildNodes)
                {
                    if (childNode.Attributes == null || childNode.Attributes["rel"] == null)
                        continue;

                    t = int.Parse(childNode.Attributes["rel"].Value);
                    if (t < _sequence)
                        _sequence = t;

                }
            }

            if (_root.Attributes != null && _root.Attributes["rel"] != null)
            {
                int t = int.Parse(_root.Attributes["rel"].Value);
                if (t == _sequence)
                    _sequence++;
            }

            List<XmlNode> reserveNodeList = new List<XmlNode>();
            List<XmlNode> removeNodeList1 = new List<XmlNode>();
            foreach (XmlNode childNode in _root.ChildNodes)
            {
                int t = int.MaxValue;

                if (childNode.Name == "br")
                {
                    continue;
                }

                if (childNode.Name == "div" || childNode.Name == "blockquote" || childNode.Name == "h3" || childNode.Name == "li")
                {
                    ProcessDiv pDiv = new ProcessDiv(childNode);
                    pDiv.Sequence = _sequence;
                    pDiv.Process();
                    _sequence = pDiv.Sequence;
                }
                else if (childNode.Name == "p")
                {
                    ProcessP paraph = new ProcessP(childNode);
                    paraph.Sequence = _sequence;
                    paraph.Process();
                    _sequence = paraph.Sequence;
                }
                else if (childNode.Name == "ul")
                {
                    ProcessUL pUL = new ProcessUL(childNode);
                    pUL.Sequence = _sequence;
                    pUL.Process();
                    _sequence = pUL.Sequence;
                }
                else if (childNode.Name == "table")
                {
                    ProcessTable pTb = new ProcessTable(childNode);
                    pTb.Sequence = _sequence;
                    pTb.Process();
                    _sequence = pTb.Sequence;
                }
                else
                {
                    //if (childNode.Name == "a")
                    //    Utility.ProcessA(childNode);
                    if (childNode.Attributes== null || childNode.Attributes["rel"] == null)
                    {
                        List<XmlNode> removeNodeList = new List<XmlNode>();
                        foreach (XmlNode cNode in childNode.ChildNodes)
                        {

                        }
                    }
                    else
                    {
                        t = int.Parse(childNode.Attributes["rel"].Value);
                        if (t == _sequence)
                        {
                            _sequence++;
                        }
                        if (t - _sequence > _root.ChildNodes.Count)
                            removeNodeList1.Add(childNode);

                        List<XmlNode> removeNodeList2 = new List<XmlNode>();
                        foreach (XmlNode cNode in childNode.ChildNodes)
                        {
                            //if (cNode.Name == "a")
                            //    Utility.ProcessA(childNode);
                            if (cNode.Attributes == null || cNode.Attributes["rel"] == null)
                                continue;
                            if (cNode.Name == "a" || cNode.Name == "i")
                            {
                                ProcessDiv pDiv = new ProcessDiv(cNode);
                                pDiv.Sequence = _sequence;
                                pDiv.Process();
                                _sequence = pDiv.Sequence;
                                continue;
                            }

                            t = int.Parse(cNode.Attributes["rel"].Value);
                            if (t == _sequence)
                            {
                                _sequence++;
                            }

                            if (t - _sequence > childNode.ChildNodes.Count)
                                removeNodeList2.Add(cNode);

                            List<XmlNode> removeNodeList3 = new List<XmlNode>();
                            foreach (XmlNode ccNode in cNode.ChildNodes)
                            {
                                //if (ccNode.Name == "a")
                                //    Utility.ProcessA(childNode);
                                if (ccNode.Attributes == null || ccNode.Attributes["rel"] == null)
                                    continue;
                                if (ccNode.Name == "a" || ccNode.Name == "i")
                                {
                                    ProcessDiv pDiv = new ProcessDiv(ccNode);
                                    pDiv.Sequence = _sequence;
                                    pDiv.Process();
                                    _sequence = pDiv.Sequence;
                                    continue;
                                }

                                t = int.Parse(ccNode.Attributes["rel"].Value);
                                if (t == _sequence)
                                {
                                    _sequence++;
                                }

                                if (t - _sequence > cNode.ChildNodes.Count || t < _sequence - 2)
                                    removeNodeList3.Add(ccNode);
                            }
                            foreach (XmlNode rNode in removeNodeList3)
                            {
                                cNode.RemoveChild(rNode);
                            }

                        }

                        foreach (XmlNode rNode in removeNodeList2)
                        {
                            childNode.RemoveChild(rNode);
                        }

                    }

                }

            }

            foreach (XmlNode rNode in removeNodeList1)
            {
                _root.RemoveChild(rNode);
            }

            //Format node
            //foreach (XmlNode childNode in _root.ChildNodes)
            //{
            //    Utility.FormatStringNode(childNode);
            //    foreach (XmlNode cNode in childNode.ChildNodes)
            //    {
            //        Utility.FormatStringNode(cNode);
            //        foreach (XmlNode ccNode in cNode.ChildNodes)
            //        {
            //            Utility.FormatStringNode(ccNode);
            //            foreach (XmlNode cccNode in ccNode.ChildNodes)
            //            {
            //                Utility.FormatStringNode(cccNode);
            //            }
            //        }
            //    }
            //}
        }
コード例 #3
0
ファイル: ProcessDoc.cs プロジェクト: VadimDang/Process_ebook
        public void Process()
        {
            XmlNode root = _doc.FirstChild;
            List<XmlNode> removeNodeList = new List<XmlNode>();
            foreach (XmlNode node in root.ChildNodes)
            {

                if (node.Name == "span")
                {
                    removeNodeList.Add(node);
                    continue;
                }

                if (node.Name == "h1" || node.Name == "h2" || node.Name == "h3" || node.Name == "h4" || node.Name == "h5" || node.Name == "h6")
                {
                    ProcessP paraph = new ProcessP(node);
                    paraph.Sequence = _sequence;
                    paraph.Process();
                    _sequence = paraph.Sequence;
                }
                else if (node.Name == "p")
                {
                    ProcessP paraph = new ProcessP(node);
                    paraph.Sequence = _sequence;
                    paraph.Process();
                    _sequence = paraph.Sequence;
                }
                else if (node.Name == "ul")
                {
                    ProcessUL pUL = new ProcessUL(node);
                    pUL.Sequence = _sequence;
                    pUL.Process();
                    _sequence = pUL.Sequence;
                }
                else if (node.Name == "table")
                {
                    ProcessTable pTb = new ProcessTable(node);
                    pTb.Sequence = _sequence;
                    pTb.Process();
                    _sequence = pTb.Sequence;
                }
                else if (node.Name == "div" || node.Name == "blockquote")
                {
                    ProcessDiv pDiv = new ProcessDiv(node);
                    pDiv.Sequence = _sequence;
                    pDiv.Process();
                    _sequence = pDiv.Sequence;
                }
                else
                {
                    ProcessDiv pDiv = new ProcessDiv(node);
                    pDiv.Sequence = _sequence;
                    pDiv.Process();
                    _sequence = pDiv.Sequence;
                }
            }

            foreach (XmlNode rNode in removeNodeList)
            {
                root.RemoveChild(rNode);
            }

            //Format
            foreach (XmlNode node in root.ChildNodes)
            {
                Utility.FormatStringNode(node);
                foreach (XmlNode childNode in node.ChildNodes)
                {
                    Utility.FormatStringNode(childNode);
                    foreach (XmlNode cNode in childNode.ChildNodes)
                    {
                        Utility.FormatStringNode(cNode);
                        foreach (XmlNode ccNode in cNode.ChildNodes)
                        {
                            Utility.FormatStringNode(ccNode);
                            foreach (XmlNode cccNode in ccNode.ChildNodes)
                            {
                                Utility.FormatStringNode(cccNode);
                                foreach (XmlNode ccccNode in cccNode.ChildNodes)
                                {
                                    Utility.FormatStringNode(ccccNode);
                                }
                            }
                        }
                    }
                }
            }
        }