コード例 #1
0
ファイル: XML.cs プロジェクト: PlumpMath/apollogeese
        private XMLNodeInteraction FindNode(IInteraction parameters)
        {
            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 (parameters.TryGetClosest(typeof(IIncomingBodiedInteraction), nodeInteraction, out candidate))
            {
                // produce an XmlNodeInteraction from that instead.
                IIncomingBodiedInteraction source = (IIncomingBodiedInteraction)candidate;

                XmlDocument document = new XmlDocument();

                document.Load(source.IncomingBody);

                nodeInteraction = new XMLNodeInteraction(parameters, document, source);
            }

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

            return(nodeInteraction);
        }
コード例 #2
0
ファイル: XML.cs プロジェクト: PlumpMath/apollogeese
        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, preceeding.Source));
                }
                else if (this.AnyNode != null)
                {
                    successful &= this.AnyNode.TryProcess(new XMLNodeInteraction(parameters, child, preceeding.Source));
                }
            }

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

            return(successful);
        }