private XmlDocument SetDescription(XmlNode extraField, string description) { XmlNode newExtra; var source = (XmlDocument)extraField; if (source == null) { source = new XmlDocument(); source.LoadXml("<extra><fileDescription>" + description + "</fileDescription></extra>"); } else { if (XmlUtility.GetXmlNodeByName(extraField, "fileDescription") == null) { XmlNode t = XmlUtility.CreateNode("fileDescription", source); t.InnerText = description; source.DocumentElement.AppendChild(t); } else { var descNodes = source.SelectNodes("/extra/fileDescription"); descNodes[0].InnerText = description; } } return(source); }
/// <summary> /// Add missing node to the desitnation document /// </summary> /// <param name="destinationParentXPath"></param> /// <param name="currentParentXPath"></param> /// <param name="parentNode"></param> /// <param name="doc"></param> /// <returns></returns> private XmlNode createMissingNodes(string destinationParentXPath, string currentParentXPath, XmlNode parentNode, XmlDocument doc) { string dif = destinationParentXPath.Substring(currentParentXPath.Length); List <string> temp = dif.Split('/').ToList(); temp.RemoveAt(0); XmlNode parentTemp = parentNode; foreach (string s in temp) { if (XmlUtility.GetXmlNodeByName(parentTemp, s) == null) { XmlNode t = XmlUtility.CreateNode(s, doc); addChild(parentTemp, t); parentTemp = t; } else { XmlNode t = XmlUtility.GetXmlNodeByName(parentTemp, s); parentTemp = t; } } return(parentTemp); }
public void CreateNode_WasCalled_ReturnXmlNode() { var result = XmlUtility.CreateNode("test", _document); Assert.IsInstanceOf <XmlNode>(result); Assert.That(result.Name, Is.EqualTo("test")); }
public static XmlDocument GenerateManifest(long datasetId, long versionId) { XmlDocument root = new XmlDocument(); XmlNode manifest = XmlUtility.CreateNode("manifest", root); XmlElement elem = root.CreateElement("datasetId"); elem.InnerText = datasetId.ToString(); manifest.AppendChild(elem); elem = root.CreateElement("datasetversionid"); elem.InnerText = versionId.ToString(); manifest.AppendChild(elem); elem = root.CreateElement("generationtime"); elem.InnerText = DateTime.UtcNow.ToString(); manifest.AppendChild(elem); root.AppendChild(manifest); return(root); }
public void CreateNode_DocumentNotExist_ReturnFalse() { var result = XmlUtility.CreateNode("test", null); Assert.IsNull(result); }
public void CreateNode_NodeNameIsNotValid_ReturnFalse(string name) { var result = XmlUtility.CreateNode(name, _document); Assert.IsNull(result); }