BExISMigration.MetadataCreator.AddReferenceToMetadatStructure C# (CSharp) Method

AddReferenceToMetadatStructure() private method

private AddReferenceToMetadatStructure ( MetadataStructure metadataStructure, string nodeName, string nodePath, string destinationPath, XmlDocument xmlDoc ) : XmlDocument
metadataStructure BExIS.Dlm.Entities.MetadataStructure.MetadataStructure
nodeName string
nodePath string
destinationPath string
xmlDoc System.Xml.XmlDocument
return System.Xml.XmlDocument
        private XmlDocument AddReferenceToMetadatStructure(MetadataStructure metadataStructure, string nodeName, string nodePath, string destinationPath, XmlDocument xmlDoc)
        {
            XmlDocument doc = xmlDoc;
            XmlNode extra;

            if (doc.DocumentElement == null)
            {
                if (metadataStructure.Extra != null)
                {

                    extra = ((XmlDocument)metadataStructure.Extra).DocumentElement;
                }
                else
                {
                    extra = doc.CreateElement("extra", "");
                }

                doc.AppendChild(extra);
            }

            XmlNode x = createMissingNodes(destinationPath, doc.DocumentElement, doc, nodeName);

            //check attrviute of the xmlnode
            if (x.Attributes.Count > 0)
            {

                foreach (XmlAttribute attr in x.Attributes)
                {
                    if (attr.Name == "name") attr.Value = nodeName;
                    if (attr.Name == "value") attr.Value = nodePath;
                }
            }
            else
            {
                XmlAttribute name = doc.CreateAttribute("name");
                name.Value = nodeName;
                XmlAttribute value = doc.CreateAttribute("value");
                value.Value = nodePath;

                x.Attributes.Append(name);
                x.Attributes.Append(value);

            }

            return doc;
        }