Example #1
0
        /// <summary>
        /// Set atribute value on a DocumentFragment based on it's xPath.
        /// If intermediate nodes are not available then this function create those nodes too.
        /// </summary>
        /// <param name="currentDocument"></param>
        /// <param name="newFragment"></param>
        public static void AddDocumentFragment(this DocumentFragment document, string xPath, string value)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }

            if (string.IsNullOrEmpty(xPath))
            {
                throw new ArgumentNullException("xPath");
            }

            string attributeName = xPath.Substring(xPath.LastIndexOf(document.Pluglet.PathSeperator) + document.Pluglet.PathSeperator.Length);

            ILogger logger = LoggerFactory.Logger;

            logger.Debug("DocumentFragmentExtensions.AddDocumentFragment", "Adding attribute {0}", attributeName);

            DocumentFragment documentFragment = document.AddIntermediateDocumentFragment(xPath);

            if (documentFragment.Attributes == null)
            {
                documentFragment.Attributes = new Dictionary <string, string>();
            }
            documentFragment.Attributes.Add(attributeName, value);

            logger.Debug("DocumentFragmentExtensions.AddDocumentFragment", "Adding attribute {0}", attributeName);
        }
Example #2
0
        /// <summary>
        /// Add new DocumentFragment based on it's xPath. If intermediate nodes are not available then this function create those nodes too.
        /// </summary>
        /// <param name="currentDocument"></param>
        /// <param name="newFragment"></param>
        public static void AddDocumentFragment(this DocumentFragment document, IDocumentFragment newFragment)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }

            if (newFragment == null)
            {
                throw new ArgumentNullException("newFragment");
            }

            ILogger logger = LoggerFactory.Logger;

            logger.Debug("DocumentFragmentExtensions.AddDocumentFragment", "Adding document fragment {0}", newFragment.Name);

            DocumentFragment parentFragment = document.AddIntermediateDocumentFragment(newFragment.Pluglet.Path);

            if (parentFragment.Children == null)
            {
                parentFragment.Children = new List <IDocumentFragment>();
            }
            parentFragment.Children.Add(newFragment);
            ((DocumentFragment)newFragment).Parent = parentFragment;

            logger.Debug("DocumentFragmentExtensions.AddDocumentFragment", "Added document fragment {0}", newFragment.Name);
        }