Пример #1
0
        private XMLNodeInteraction FindNode(IInteraction parameters)
        {
            TextReader         reader;
            IInteraction       candidate;
            XMLNodeInteraction nodeInteraction = null;

            // find an XmlNodeInteraction and hold on to that
            if (parameters.TryGetClosest(typeof(XMLNodeInteraction), out candidate))
            {
                nodeInteraction = (XMLNodeInteraction)candidate;
            }

            // But if a new incoming body was acquired after that
            if (TryGetDatareader(parameters, nodeInteraction, out reader))
            {
                XmlDocument document = new XmlDocument();

                document.Load(reader);

                if (this.IsForwardSourcing)
                {
                    reader.Close();
                }

                nodeInteraction = new XMLNodeInteraction(parameters, document);
            }

            if (nodeInteraction == null)
            {
                // bitter failure
                throw new Exception("Couldn't find or produce XML document");
            }

            return(nodeInteraction);
        }
Пример #2
0
        protected override bool Process(IInteraction parameters)
        {
            XMLNodeInteraction preceeding = FindNode(parameters);
            string             name;
            bool successful = true;

            XmlNodeList children;

            if (this.Path.Length > 0)
            {
                children = preceeding.Node.SelectNodes(this.Path);
            }

            else
            {
                children = preceeding.Node.ChildNodes;
            }


            foreach (XmlNode child in children)
            {
                name = child.LocalName.TrimStart('#');

                if (Branches.Has(name))
                {
                    successful &= Branches[name].TryProcess(new XMLNodeInteraction(parameters, child));
                }
                else if (this.AnyNode != null)
                {
                    successful &= this.AnyNode.TryProcess(new XMLNodeInteraction(parameters, child));
                }
            }

            if ((children.Count == 0) && (this.NoNode != null))
            {
                successful &= this.NoNode.TryProcess(parameters);
            }

            return(successful);
        }