private void LoadRowData(DataRow row, XmlElement rowElement)
{
XmlNode n;
DataTable table = row.Table;
if (FromInference)
table.Prefix = rowElement.Prefix;
// keep a list of all columns that get updated
Hashtable foundColumns = new Hashtable();
row.BeginEdit();
// examine all children first
n = rowElement.FirstChild;
// Look for data to fill the TextOnly column
DataColumn column = GetTextOnlyColumn(row);
if (column != null)
{
foundColumns[column] = column;
string text = GetValueForTextOnlyColums(n);
if (XMLSchema.GetBooleanAttribute(rowElement, Keywords.XSI_NIL, Keywords.XSINS, false) && string.IsNullOrEmpty(text))
row[column] = DBNull.Value;
else
SetRowValueFromXmlText(row, column, text);
}
// Walk the region to find elements that map to columns
while (n != null && n != rowElement)
{
if (n.NodeType == XmlNodeType.Element)
{
XmlElement e = (XmlElement)n;
object schema = _nodeToSchemaMap.GetSchemaForNode(e, FIgnoreNamespace(e));
if (schema is DataTable)
{
if (FColumnElement(e))
schema = _nodeToSchemaMap.GetColumnSchema(e, FIgnoreNamespace(e));
}
// if element has its own table mapping, it is a separate region
if (schema == null || schema is DataColumn)
{
// descend to examine child elements
n = e.FirstChild;
if (schema != null && schema is DataColumn)
{
DataColumn c = (DataColumn)schema;
if (c.Table == row.Table && c.ColumnMapping != MappingType.Attribute && foundColumns[c] == null)
{
foundColumns[c] = c;
string text = GetValueForTextOnlyColums(n);
if (XMLSchema.GetBooleanAttribute(e, Keywords.XSI_NIL, Keywords.XSINS, false) && string.IsNullOrEmpty(text))
row[c] = DBNull.Value;
else
SetRowValueFromXmlText(row, c, text);
}
}
else if ((schema == null) && (n != null))
{
continue;
}
// nothing left down here, continue from element
if (n == null)
n = e;
}
}
// if no more siblings, ascend back toward original element (rowElement)
while (n != rowElement && n.NextSibling == null)
{
n = n.ParentNode;
}
if (n != rowElement)
n = n.NextSibling;
}
//
// Walk the attributes to find attributes that map to columns.
//
foreach (XmlAttribute attr in rowElement.Attributes)
{
object schema = _nodeToSchemaMap.GetColumnSchema(attr, FIgnoreNamespace(attr));
if (schema != null && schema is DataColumn)
{
DataColumn c = (DataColumn)schema;
if (c.ColumnMapping == MappingType.Attribute && foundColumns[c] == null)
{
foundColumns[c] = c;
n = attr.FirstChild;
SetRowValueFromXmlText(row, c, GetInitialTextFromNodes(ref n));
}
}
}
// Null all columns values that aren't represented in the tree
foreach (DataColumn c in row.Table.Columns)
{
if (foundColumns[c] == null && XmlToDatasetMap.IsMappedColumn(c))
{
if (!c.AutoIncrement)
{
if (c.AllowDBNull)
{
row[c] = DBNull.Value;
}
else
{
row[c] = c.DefaultValue;
}
}
else
{
c.Init(row._tempRecord);
}
}
}
row.EndEdit();
}