private NewElementCreateData GetElementCreateData(object persistee) { Debug.Assert(persistee != null, "persistee is null"); IXmlTestStoreCustom custom = persistee as IXmlTestStoreCustom; NewElementCreateData toReturn = new NewElementCreateData(); if (custom != null) { toReturn.ElementName = custom.ElementName; toReturn.NamespaceUri = custom.NamespaceUri; } if (toReturn.ElementName == null) { toReturn.ElementName = persistee.GetType().Name; } if (toReturn.NamespaceUri == null) { toReturn.NamespaceUri = this.namespaceUri; } return(toReturn); }
/// <summary> /// Based on the StoreXml* attributes saves simple fields /// </summary> /// <param name="objectToSave"> /// The object to save. /// </param> /// <param name="parentXml"> /// The parent xml. /// </param> /// <param name="location"> /// The location. /// </param> /// <param name="parameters"> /// The parameters. /// </param> public void SaveObject(object objectToSave, XmlElement parentXml, string location, XmlTestStoreParameters parameters) { if (objectToSave != null && location != null) { string nameSpaceUri = this.namespaceUri; IXmlTestStoreCustom customStore = objectToSave as IXmlTestStoreCustom; if (customStore != null) { nameSpaceUri = customStore.NamespaceUri; } XmlNode xmlNode = this.EnsureLocationExists(parentXml, location, nameSpaceUri); this.SaveObject(objectToSave, xmlNode, parameters); XmlElement element = xmlNode as XmlElement; if (element != null && !element.HasAttributes && !element.HasChildNodes && string.IsNullOrEmpty(element.InnerText)) { element.ParentNode.RemoveChild(element); // get rid of empty elements to keep the xml clean } } }