Exemple #1
0
        public bool Contains_Path(GenericXmlPath Path)
        {
            if (searchNodes.Count == 0)
            {
                build_search_tree();
            }

            // Look for a match
            if (searchNodes.ContainsKey(Path.PathNodes[0].NodeName))
            {
                GenericXmlMappingTreeNode lastMatchingNode = searchNodes[Path.PathNodes[0].NodeName];
                int index = 1;
                while (index < Path.PathNodes.Count)
                {
                    string nextNodeName = Path.PathNodes[index].NodeName;
                    if (!lastMatchingNode.Children.ContainsKey(nextNodeName))
                    {
                        return(false);
                    }

                    lastMatchingNode = lastMatchingNode.Children[nextNodeName];

                    index++;
                }

                // If there are instructions here, return them
                return(true);
            }

            return(false);
        }
Exemple #2
0
        public PathMappingInstructions Get_Matching_Path_Instructions(GenericXmlPath Path, string AttributeName)
        {
            if (searchNodes.Count == 0)
            {
                build_search_tree();
            }

            // Look for a match
            if (searchNodes.ContainsKey(Path.PathNodes[0].NodeName))
            {
                GenericXmlMappingTreeNode lastMatchingNode = searchNodes[Path.PathNodes[0].NodeName];
                int index = 1;
                while (index < Path.PathNodes.Count)
                {
                    string nextNodeName = Path.PathNodes[index].NodeName;
                    if (!lastMatchingNode.Children.ContainsKey(nextNodeName))
                    {
                        return(null);
                    }

                    lastMatchingNode = lastMatchingNode.Children[nextNodeName];

                    index++;
                }

                // If there are instructions here, return them
                if ((lastMatchingNode.AttributeInstructions != null) && (lastMatchingNode.AttributeInstructions.ContainsKey(AttributeName)))
                {
                    return(lastMatchingNode.AttributeInstructions[AttributeName]);
                }
            }

            return(null);
        }
Exemple #3
0
        private void build_search_tree()
        {
            searchNodes.Clear();

            foreach (GenericXmlMappingPath mapping in Mappings)
            {
                // Handle the first node first
                if ((mapping.XmlPath != null) && (mapping.XmlPath.PathNodes != null) && (mapping.XmlPath.PathNodes.Count > 0))
                {
                    // Handle the root node
                    GenericXmlMappingTreeNode rootNode = null;
                    if (searchNodes.ContainsKey(mapping.XmlPath.PathNodes[0].NodeName))
                    {
                        rootNode = searchNodes[mapping.XmlPath.PathNodes[0].NodeName];
                    }
                    else
                    {
                        rootNode      = new GenericXmlMappingTreeNode();
                        rootNode.Node = mapping.XmlPath.PathNodes[0];
                        searchNodes[mapping.XmlPath.PathNodes[0].NodeName] = rootNode;
                    }

                    // Was this the only node?
                    if (mapping.XmlPath.PathNodes.Count == 1)
                    {
                        if (!String.IsNullOrEmpty(mapping.XmlPath.AttributeName))
                        {
                            rootNode.AttributeInstructions[mapping.XmlPath.AttributeName] = mapping.Instructions;
                        }
                        else
                        {
                            rootNode.Instructions = mapping.Instructions;
                        }
                    }
                    else
                    {
                        int i = 0;
                        while ((i + 1) < mapping.XmlPath.PathNodes.Count)
                        {
                            i++;

                            if (rootNode.Children.ContainsKey(mapping.XmlPath.PathNodes[i].NodeName))
                            {
                                rootNode = rootNode.Children[mapping.XmlPath.PathNodes[i].NodeName];
                            }
                            else
                            {
                                GenericXmlMappingTreeNode newChildNode = new GenericXmlMappingTreeNode();
                                newChildNode.Node = mapping.XmlPath.PathNodes[i];
                                rootNode.Children[mapping.XmlPath.PathNodes[i].NodeName] = newChildNode;
                                rootNode = newChildNode;
                            }
                        }

                        // ASsign instructions here
                        if (!String.IsNullOrEmpty(mapping.XmlPath.AttributeName))
                        {
                            rootNode.AttributeInstructions[mapping.XmlPath.AttributeName] = mapping.Instructions;
                        }
                        else
                        {
                            rootNode.Instructions = mapping.Instructions;
                        }
                    }
                }
            }
        }
        private void build_search_tree()
        {
            searchNodes.Clear();

            foreach (GenericXmlMappingPath mapping in Mappings)
            {
                // Handle the first node first
                if (( mapping.XmlPath != null ) && ( mapping.XmlPath.PathNodes != null ) && ( mapping.XmlPath.PathNodes.Count > 0 ))
                {
                    // Handle the root node
                    GenericXmlMappingTreeNode rootNode = null;
                    if (searchNodes.ContainsKey(mapping.XmlPath.PathNodes[0].NodeName))
                    {
                        rootNode = searchNodes[mapping.XmlPath.PathNodes[0].NodeName];
                    }
                    else
                    {
                        rootNode = new GenericXmlMappingTreeNode();
                        rootNode.Node = mapping.XmlPath.PathNodes[0];
                        searchNodes[mapping.XmlPath.PathNodes[0].NodeName] = rootNode;
                    }

                    // Was this the only node?
                    if (mapping.XmlPath.PathNodes.Count == 1)
                    {
                        if (!String.IsNullOrEmpty(mapping.XmlPath.AttributeName))
                            rootNode.AttributeInstructions[mapping.XmlPath.AttributeName] = mapping.Instructions;
                        else
                            rootNode.Instructions = mapping.Instructions;
                    }
                    else
                    {
                        int i = 0;
                        while ((i + 1) < mapping.XmlPath.PathNodes.Count)
                        {
                            i++;

                            if (rootNode.Children.ContainsKey(mapping.XmlPath.PathNodes[i].NodeName))
                            {
                                rootNode = rootNode.Children[mapping.XmlPath.PathNodes[i].NodeName];
                            }
                            else
                            {
                                GenericXmlMappingTreeNode newChildNode = new GenericXmlMappingTreeNode();
                                newChildNode.Node = mapping.XmlPath.PathNodes[i];
                                rootNode.Children[mapping.XmlPath.PathNodes[i].NodeName] = newChildNode;
                                rootNode = newChildNode;
                            }
                        }

                        // ASsign instructions here
                        if (!String.IsNullOrEmpty(mapping.XmlPath.AttributeName))
                            rootNode.AttributeInstructions[mapping.XmlPath.AttributeName] = mapping.Instructions;
                        else
                            rootNode.Instructions = mapping.Instructions;
                    }
                }
            }
        }