예제 #1
0
        /// <summary>
        /// Build a XmlTree from a xml NAnt script file.
        /// </summary>
        /// <param name="filename">Xml fileName.</param>
        /// <param name="showInclude">Add include file in tree.</param>
        /// <returns>XmlTree for the script file.</returns>
        internal static XmlTree CreateXmlTree(string filename, bool showInclude)
        {
            XmlTree nodeTree = null;

            // Parse the file
            XmlNode rootNode = ParseXmlFile(filename);

            // Create the tree from the root node
            if (rootNode != null)
            {
                nodeTree = new XmlTree(rootNode);

                // Insert include script in the three
                if (showInclude)
                {
                    // Folder of the script to resolve include
                    string folder = Path.GetDirectoryName(filename);
                    ParseIncludeFiles(folder, nodeTree);
                }
            }

            return(nodeTree);
        }
예제 #2
0
        /// <summary>
        /// Insert script tree from include file in a XmlTree.
        /// </summary>
        /// <param name="folder">Folder base of the includer file.</param>
        /// <param name="tree">XmlTree to be updated.</param>
        private static void ParseIncludeFiles(string folder, XmlTree tree)
        {
            foreach (XmlNode include in tree.Includes)
            {
                // Path of included file
                string includedPath = "";

                try
                {
                    // Try to combine the folder base and include path
                    includedPath = Path.Combine(folder, include[AppConstants.NANT_XML_BUILDFILE]);
                }
                catch
                {
                    // ignored
                }

                // Build tree from file
                XmlTree subTree = CreateXmlTree(includedPath, true);

                // Add to the main tree
                tree.Root.Add(subTree.Root.Children);
            }
        }