Exemplo n.º 1
0
        /// <summary>
        /// Clears any elements that compare as equal based on the schema particles. For example, equivalent choice
        /// items will be removed.
        /// </summary>
        public void Clear()
        {
            var enumerator = new OpenXmlCompositeElementEnumerator(this);

            // We track an item to remove and do it after the enumerator is advanced to we don't try to remove
            // the current element which would break the enumeration.
            var remove = default(OpenXmlElement);

            while (enumerator.MoveNext())
            {
                if (remove != null)
                {
                    remove.Remove();
                    remove = null;
                }

                var data    = enumerator.Current;
                var current = _compiled.Find(data);

                if (current != null && current.Equals(_elementPath))
                {
                    remove = data;
                }
            }

            if (remove != null)
            {
                remove.Remove();
            }
        }
Exemplo n.º 2
0
        private OpenXmlElement GetNode()
        {
            var enumerator = new OpenXmlCompositeElementEnumerator(this);

            while (enumerator.MoveNext())
            {
                var data     = enumerator.Current;
                var compared = _elementPath.CompareTo(enumerator.Path);

                if (compared < 0)
                {
                    return(data.PreviousSibling());
                }
                else if (compared == 0)
                {
                    var result = enumerator.Current;

                    while (enumerator.MoveNext() && enumerator.Path.Equals(_elementPath))
                    {
                        result = enumerator.Current;
                    }

                    return(result);
                }
                else if (data == _element.LastChild)
                {
                    return(data);
                }
            }

            return(null);
        }