System.Data.XmlTreeGen.HandleRelation C# (CSharp) Method

HandleRelation() private method

private HandleRelation ( DataRelation rel, XmlDocument dc ) : XmlElement
rel DataRelation
dc XmlDocument
return XmlElement
        internal XmlElement HandleRelation(DataRelation rel, XmlDocument dc)
        {
            XmlElement root = dc.CreateElement(Keywords.MSD, Keywords.MSD_RELATION, Keywords.MSDNS);

            // convert relation name to valid xml name
            root.SetAttribute(Keywords.NAME, XmlConvert.EncodeLocalName(rel.RelationName));

            root.SetAttribute(Keywords.MSD_PARENT, Keywords.MSDNS, rel.ParentKey.Table.EncodedTableName);
            root.SetAttribute(Keywords.MSD_CHILD, Keywords.MSDNS, rel.ChildKey.Table.EncodedTableName);

            if ((_ds == null) || (_ds.Tables.InternalIndexOf(rel.ParentKey.Table.TableName) == -3))
                root.SetAttribute(Keywords.MSD_PARENTTABLENS, Keywords.MSDNS, rel.ParentKey.Table.Namespace);

            if ((_ds == null) || (_ds.Tables.InternalIndexOf(rel.ChildKey.Table.TableName) == -3))
                root.SetAttribute(Keywords.MSD_CHILDTABLENS, Keywords.MSDNS, rel.ChildKey.Table.Namespace);

            DataColumn[] key = rel.ParentKey.ColumnsReference;

            string text = key[0].EncodedColumnName;
            StringBuilder builder = null;
            if (1 < key.Length)
            {
                builder = new StringBuilder();
                builder.Append(text);
                for (int i = 1; i < key.Length; i++)
                {
                    builder.Append(Keywords.MSD_KEYFIELDSEP).Append(key[i].EncodedColumnName);
                }
                text = builder.ToString();
            }
            root.SetAttribute(Keywords.MSD_PARENTKEY, Keywords.MSDNS, text);

            key = rel.ChildKey.ColumnsReference;
            text = key[0].EncodedColumnName;
            if (1 < key.Length)
            {
                if (null != builder)
                {
                    builder.Length = 0;
                }
                else
                {
                    builder = new StringBuilder();
                }
                builder.Append(text);
                for (int i = 1; i < key.Length; i++)
                {
                    builder.Append(Keywords.MSD_KEYFIELDSEP).Append(key[i].EncodedColumnName);
                }
                text = builder.ToString();
            }
            root.SetAttribute(Keywords.MSD_CHILDKEY, Keywords.MSDNS, text);
            AddExtendedProperties(rel._extendedProperties, root);
            return root;
        }