public XmlAttributeValueChange(XmlNodePath elementPath, XName key, string newValue, string oldValue)
 {
     ElementPath = elementPath;
     Key         = key;
     NewValue    = newValue;
     OldValue    = oldValue;
 }
예제 #2
0
        public static bool TryParse(string str, out XmlNodePath path)
        {
            path = null;
            var parts = str.Split(new[] { '/' }, StringSplitOptions.None);

            if (parts.Length < 1)
            {
                return(false);
            }
            if (parts[0] != string.Empty)
            {
                return(false);
            }
            var indexes = new int[parts.Length - 1];

            for (var i = 1; i < parts.Length; i++)
            {
                int index;
                if (int.TryParse(parts[i], out index))
                {
                    indexes[i - 1] = index;
                }
            }
            path = new XmlNodePath(indexes);
            return(true);
        }
예제 #3
0
 public XmlAddNodeChange(XmlNodePath path, IImmutableXNode node)
 {
     if (path == null)
     {
         throw new ArgumentNullException("path");
     }
     Path = path;
     Node = node;
 }
예제 #4
0
 public XmlTextValueChangeBase(XmlNodePath path, string newValue, string oldValue)
 {
     if (path == null)
     {
         throw new ArgumentNullException("path");
     }
     Path     = path;
     NewValue = newValue;
     OldValue = oldValue;
 }
예제 #5
0
        /// <summary>
        ///     Conditionally removes a node from a document at specified node path.
        ///     If <paramref name="comparedNode" /> is provided, the node also has to
        ///     be equal to this to be removed.
        /// </summary>
        /// <param name="doc">The document to remove from</param>
        /// <param name="nodePath">The path of the node to remove</param>
        /// <param name="comparedNode">Node to compare with before removing. Can be null.</param>
        /// <returns>True if node was removed, false if not found or not equal to comparedNode.</returns>
        public static bool TryRemove(this XDocument doc, XmlNodePath nodePath, XNode comparedNode = null)
        {
            XNode removed;

            nodePath.TryFind(doc, out removed);
            if (removed == null || comparedNode != null && !comparedNode.DeepEquals(removed))
            {
                return(false);
            }

            removed.Remove();
            return(true);
        }
예제 #6
0
        internal static bool TryAddAttribute(XDocument doc, XmlNodePath elementPath, XName key, string value)
        {
            XElement element;

            if (!elementPath.TryFind(doc, out element))
            {
                return(false);
            }

            // Fail if attribute already exists
            if (element.Attribute(key) != null)
            {
                return(false);
            }

            // TODO: Think about attribute index?
            element.Add(new XAttribute(key, value));
            return(true);
        }
예제 #7
0
        internal static bool TryRemoveAttribute(XDocument doc, XmlNodePath elementPath, XName key, string value)
        {
            XElement element;

            if (!elementPath.TryFind(doc, out element))
            {
                return(false);
            }

            // Fail if attribute already exists
            var attribute = element.Attribute(key);

            if (attribute == null || attribute.Value != value)
            {
                return(false);
            }

            attribute.Remove();

            // TODO: Think about attribute index?
            return(true);
        }
예제 #8
0
 public static XmlNodePath NodePath(this XNode node)
 {
     return(XmlNodePath.From(node));
 }
 public XmlAddAttributeChange(XmlNodePath elementPath, XName key, string value)
 {
     _elementPath = elementPath;
     Key          = key;
     Value        = value;
 }
예제 #10
0
 public XmlCDataValueChange(XmlNodePath path, string newValue, string oldValue) : base(path, newValue, oldValue)
 {
 }
예제 #11
0
 /// <summary>
 ///     Conditionally inserts a node into a document at specified node path.
 /// </summary>
 /// <param name="doc">The document to insert to</param>
 /// <param name="nodePath">The path the node will have after being inserted</param>
 /// <param name="inserted">The inserted node</param>
 /// <returns>True if node was inserted, false if parent of path could not be found</returns>
 public static bool TryInsert(this XDocument doc, XmlNodePath nodePath, XNode inserted)
 {
     return(nodePath.TryInsertToDocument(doc, inserted));
 }