private void FixNestedChildren(DataRow row, XmlElement rowElement)
{
foreach (DataRelation dr in GetNestedChildRelations(row))
{
foreach (DataRow r in row.GetChildRows(dr))
{
XmlElement childElem = r.Element;
// childElem can be null when we create XML from DataSet (XmlDataDocument( DataSet ) is called) and we insert rowElem of the parentRow before
// we insert the rowElem of children rows.
if (childElem != null)
{
#if DEBUG
bool fIsChildConnected = IsConnected(childElem);
#endif
if (childElem.ParentNode != rowElement)
{
childElem.ParentNode.RemoveChild(childElem);
rowElement.AppendChild(childElem);
}
#if DEBUG
// We should not have changed the connected/disconnected state of the node (since the row state did not change)
Debug.Assert(fIsChildConnected == IsConnected(childElem));
Debug.Assert(IsRowLive(r) ? IsConnected(childElem) : !IsConnected(childElem));
#endif
}
}
}
}