Beispiel #1
0
        /// <summary>
        /// Gets the attribute or child (in this order) of the given <see cref="XmlElement"/> with the given name.
        /// </summary>
        private static string GetAttributeOrChild(this XmlElement element, string name)
        {
            var attribute = element.GetAttribute(name);

            if (attribute.HasValue())
            {
                return(attribute);
            }

            return(element.SelectNode(name)?.InnerText);
        }
Beispiel #2
0
        /// <summary>
        /// Sets the attribute or child (in this order) of the given <see cref="XmlElement"/> with the given name.
        /// </summary>
        private static void SetAttributeOrChild(this XmlElement element, string name, string value)
        {
            var attribute = element.GetAttribute(name);

            if (attribute.HasValue())
            {
                element.SetAttribute(name, value);
            }
            else
            {
                var node = element.SelectNode(name);

                if (node != null)
                {
                    node.InnerText = value;
                }
            }
        }