/// <summary> /// Compares this object with another by value. /// </summary> public override bool Equals(object obj) { // Compare nullability and type var other = obj as XmlAnyDocument; if (ReferenceEquals(other, null)) { return(false); } // Compare values return (Xml != null && other.Xml != null && Xml.CreateNavigator().OuterXml == other.Xml.CreateNavigator().OuterXml); }
/// <summary> /// Returns an <see cref="XPathNavigator"/> positioned within the data. /// Parent elements in the path without filters will be created if the <paramref name="create"/> option is set. /// (up to the first filter). /// </summary> /// <remarks> /// Even if this instance was serialized standalone the default "root" element is not part of the path because it is stripped during de-serialization. /// </remarks> /// <param name="path">Optional XPath expression to select the sub-path. Set null to select the root element.</param> /// <param name="create">Create the path if it doesn't exist.</param> /// <returns><see cref="XPathNavigator"/> positioned at the path or null when not found and <paramref name="create"/> was not set true.</returns> public XPathNavigator GetPath(string path, bool create) { // Return document root when no path if (String.IsNullOrEmpty(path)) { return(Xml.CreateNavigator()); } // Attempt to get path var result = Xml.CreateNavigator().SelectSingleNode(path); if (create && result == null) { // Create path when not found and requested result = Xml.CreateNavigator(); foreach (var pathPart in path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)) { // Check if next part exists if (result != null) { var child = result.SelectSingleNode(pathPart); if (child == null) { // Return null when path includes filter (cannot automatically create conditional content) if (pathPart.IndexOf('[') >= 0) { return(null); } // Create path parts which do not exist result.AppendChildElement("", pathPart, "", null); child = result.SelectSingleNode(pathPart); } // Next/last part result = child; } } } // Return result return(result); }
/// <summary> /// Returns an <see cref="XPathNavigator"/> positioned at the root of the data. /// </summary> public XPathNavigator GetRoot() { return(Xml.CreateNavigator()); }
public virtual IElement Add(object content) { if (content == null #if DBDATA || content == DBNull.Value #endif ) { return(this); } if (content is Element elem && elem.Xml != null) { Xml.AppendChild(Xml.OwnerDocument.ImportNode(elem.Xml, true)); return(this); } if (content is Item item && item.nodeList != null) { foreach (var node in item.nodeList.OfType <XmlNode>()) { Xml.AppendChild(Xml.OwnerDocument.ImportNode(node, true)); } return(this); } if (content is IAmlNode aml) { using (var writer = Xml.CreateNavigator().AppendChild()) aml.ToAml(writer); return(this); } if (content is IReadOnlyAttribute attr) { Xml.SetAttribute(attr.Name, attr.Value); return(this); } if (content is string str) { Xml.InnerText = str; return(this); } var enumerable = content as IEnumerable; if (enumerable != null) { foreach (var curr in enumerable) { Add(curr); } return(this); } if (content is XmlElement xElem) { var imported = Xml.OwnerDocument.ImportNode(xElem, true); Xml.AppendChild(imported); return(this); } Xml.InnerText = AmlContext.LocalizationContext.Format(content); return(this); }