BExIS.Xml.Helpers.Mapping.XmlMapperManager.addChild C# (CSharp) Method

addChild() private method

Add Child to a node based on the selected schema the child will added to the schema defined index
private addChild ( XmlNode node, XmlNode child ) : XmlNode
node System.Xml.XmlNode parent xmlnode
child System.Xml.XmlNode child xmlnode
return System.Xml.XmlNode
        private XmlNode addChild(XmlNode node, XmlNode child)
        {
            //node has no childrens --> add it
            if (node.ChildNodes.Count == 0)
                node.AppendChild(child);

            //has childrens, need to find the rigth position of the new element
            else
            {
                int index = xmlSchemaManager.GetIndexOfChild(node, child);
                if (index != -1)
                {
                    bool added = false;
                    foreach (XmlNode seqChild in node.ChildNodes)
                    {
                        if (index < xmlSchemaManager.GetIndexOfChild(node, seqChild))
                        {
                            node.InsertBefore(child, seqChild);
                            added = true;
                        }
                    }

                    if (!added)
                    {
                        node.AppendChild(child);
                    }
                }
                else
                {
                    node.AppendChild(child);
                }

            }

            return node;
        }