private void WriteDataSetElement ()
{
w.WriteStartElement ("xs", "element", xmlnsxs);
w.WriteAttributeString ("name", XmlHelper.Encode (dataSetName));
w.WriteAttributeString (XmlConstants.MsdataPrefix,
"IsDataSet", XmlConstants.MsdataNamespace,
"true");
#if NET_2_0
bool useCurrentLocale = (dataSetLocale == null);
if (!useCurrentLocale)
#endif
{
w.WriteAttributeString (
XmlConstants.MsdataPrefix,
"Locale",
XmlConstants.MsdataNamespace,
dataSetLocale.Name);
}
#if NET_2_0
if(mainDataTable != null && mainDataTable != "")
w.WriteAttributeString (
XmlConstants.MsdataPrefix,
"MainDataTable",
XmlConstants.MsdataNamespace,
mainDataTable);
if (useCurrentLocale) {
w.WriteAttributeString (
XmlConstants.MsdataPrefix,
"UseCurrentLocale",
XmlConstants.MsdataNamespace,
"true");
}
#endif
AddExtendedPropertyAttributes (dataSetProperties);
w.WriteStartElement ("xs", "complexType", xmlnsxs);
w.WriteStartElement ("xs", "choice", xmlnsxs);
w.WriteAttributeString ("minOccurs", "0");
w.WriteAttributeString ("maxOccurs", "unbounded");
foreach (DataTable table in tables) {
bool isTopLevel = true;
foreach (DataRelation rel in table.ParentRelations) {
if (rel.Nested) {
isTopLevel = false;
break;
}
}
// If there is a relation but only one table, could be that
// we have to add a ref attribute
bool addref = false;
if (!isTopLevel && tables.Length < 2) {
isTopLevel = true;
addref = true;
}
if (isTopLevel) {
if (dataSetNamespace != table.Namespace ||
addref) {
// <xs:element ref="X:y" />
w.WriteStartElement ("xs",
"element",
xmlnsxs);
w.WriteStartAttribute ("ref", String.Empty);
w.WriteQualifiedName (XmlHelper.Encode (table.TableName), table.Namespace);
w.WriteEndAttribute ();
w.WriteEndElement ();
}
else
WriteTableElement (table);
}
}
w.WriteEndElement (); // choice
w.WriteEndElement (); // complexType
WriteConstraints (); // DataSet constraints
w.WriteEndElement (); // element
if (annotation.Count > 0) {
w.WriteStartElement ("xs", "annotation", xmlnsxs);
w.WriteStartElement ("xs", "appinfo", xmlnsxs);
foreach (object o in annotation) {
if (!(o is DataRelation))
continue;
WriteDataRelationAnnotation ((DataRelation)o);
}
w.WriteEndElement ();
w.WriteEndElement ();
}
}