public override XmlElement CreateElement(string prefix, string localName, string namespaceURI)
{
// There are three states for the document:
// - special listeners ON, no permananent listeners: this is when the data doc was created w/o any dataset, and the 1st time a new row/element
// is created we should subscribe the permenent listeners.
// - special listeners OFF, permanent listeners ON: this is when the data doc is loaded (from dataset or XML file) and synchronization takes place.
// - special listeners OFF, permanent listeners OFF: this is then the data doc is LOADING (from dataset or XML file) - the synchronization is done by code,
// not based on listening to events.
#if DEBUG
// Cannot have both special and permananent listeners ON
if (_fDataRowCreatedSpecial)
Debug.Assert((_fBoundToDataSet == false) && (_fBoundToDocument == false));
// fBoundToDataSet and fBoundToDocument should have the same value
Debug.Assert(_fBoundToDataSet ? _fBoundToDocument : (!_fBoundToDocument));
#endif
if (prefix == null)
prefix = string.Empty;
if (namespaceURI == null)
namespaceURI = string.Empty;
if (!_fAssociateDataRow)
{
// Loading state: create just the XmlBoundElement: the LoadTreeFromDataSet/LoadDataSetFromTree will take care of synchronization
return new XmlBoundElement(prefix, localName, namespaceURI, this);
}
// This is the 1st time an element is beeing created on an empty XmlDataDocument - unbind special listeners, bind permanent ones and then go on w/
// creation of this element
EnsurePopulatedMode();
Debug.Assert(_fDataRowCreatedSpecial == false);
// Loaded state: create a DataRow, this in turn will create and associate the XmlBoundElement, which we will return.
DataTable dt = _mapper.SearchMatchingTableSchema(localName, namespaceURI);
if (dt != null)
{
DataRow row = dt.CreateEmptyRow();
// We need to make sure all fields are DBNull
foreach (DataColumn col in dt.Columns)
{
if (col.ColumnMapping != MappingType.Hidden)
SetRowValueToNull(row, col);
}
XmlBoundElement be = row.Element;
Debug.Assert(be != null);
be.Prefix = prefix;
return be;
}
// No matching table schema for this element: just create the element
return new XmlBoundElement(prefix, localName, namespaceURI, this);
}