예제 #1
0
        private XmlStreamNode CreateNode()
        {
            var node = new XmlStreamNode {
                Name  = this.Name,
                Depth = this.CurDepth,
            };

            for (int attInd = 0; attInd < this.AttributeCount; attInd++)
            {
                this.MoveToAttribute(attInd);
                node.Attrib[this.Name] = this.Value;
            }
            this.MoveToElement();
            return(node);
        }
예제 #2
0
        public string ReadTexts(string path, Action <XmlStreamer, XmlStreamNode> scan)
        {
            var name      = path;
            var nms       = path.Split('/');
            var readDepth = this.CurDepth + 1;

            if (nms.Length > 1)
            {
                name = nms[0];
                path = path.Substring(name.Length + 1);
            }
            else
            {
                path = "";
            }
            string        totBody = "", body = "";
            XmlStreamNode lastElem = null;

            while (this.CurDepth >= (readDepth - 1))
            {
                if (!this.Read())
                {
                    break;
                }
                switch (this.NodeType)
                {
                case XmlNodeType.Element: {
                    if (this.IsEmptyElement)
                    {
                        continue;
                    }
                    this.CurDepth++;
                    var elem = CreateNode();
                    this.Stack.Push(elem);
                    if (readDepth == this.CurDepth && name == this.Name)
                    {
                        if (path != "")
                        {
                            if (totBody.Length > 0)
                            {
                                totBody += "\r\n";
                            }
                            totBody += this.ReadText(path, null);
                        }
                        else
                        {
                            lastElem = elem;
                        }
                    }
                    else
                    {
                        lastElem = null;
                    }
                } break;

                case XmlNodeType.EndElement: {
                    var elem = this.Stack.Pop();
                    if (this.Name != elem.Name)
                    {
                        throw new SysException("End Elem: {0} {1}", elem.Name, this.Name);
                    }
                    this.CurDepth--;
                    if (elem.Name == name)
                    {
                        if (totBody.Length > 0)
                        {
                            totBody += "\r\n";
                        }
                        totBody  += body;
                        elem.Text = body;
                        if (scan != null)
                        {
                            scan(this, elem);
                        }
                        body = "";
                    }
                    body = "";
                } break;

                case XmlNodeType.CDATA:
                case XmlNodeType.Text: {
                    if (lastElem != null)
                    {
                        if (body.Length > 0)
                        {
                            body += "\r\n";
                        }
                        body += this.Value;
                    }
                } break;
                }
            }
            return(totBody);
        }