예제 #1
0
        // get the DataRow associated with the XmlElement
        public DataRow GetRowFromElement(XmlElement e)
        {
            XmlDataElement el = e as XmlDataElement;

            if (el == null)
            {
                return(null);
            }
            return(el.DataRow);
        }
예제 #2
0
        private void FillNodeRows(XmlElement parent, DataTable dt, ICollection rows)
        {
            foreach (DataRow dr in dt.Rows)
            {
                XmlDataElement el = dr.DataElement;
                FillNodeChildrenFromRow(dr, el);

                foreach (DataRelation rel in dt.ChildRelations)
                {
                    FillNodeRows(el, rel.ChildTable, dr.GetChildRows(rel));
                }
                parent.AppendChild(el);
            }
        }
		private void FillNodeRows (XmlElement parent, DataTable dt, ICollection rows)
		{
			foreach (DataRow dr in dt.Rows) {
				XmlDataElement el = new XmlDataElement (dr, dt.Prefix, dt.TableName, dt.Namespace, this);
				for (int i = 0; i < dt.Columns.Count; i++) {
					DataColumn col = dt.Columns [i];
					string value = dr.IsNull (col) ? String.Empty : dr [col].ToString ();
					switch (col.ColumnMapping) {
					case MappingType.Element:
						XmlElement cel = CreateElement (col.Prefix, col.ColumnName, col.Namespace);
						cel.InnerText = value;
						el.AppendChild (cel);
						break;
					case MappingType.Attribute:
						XmlAttribute a = CreateAttribute (col.Prefix, col.ColumnName, col.Namespace);
						a.Value = value;
						el.SetAttributeNode (a);
						break;
					case MappingType.SimpleContent:
						XmlText t = CreateTextNode (value);
						el.AppendChild (t);
						break;
					}
				}
				foreach (DataRelation rel in dt.ChildRelations)
					FillNodeRows (el, rel.ChildTable, dr.GetChildRows (rel));
				parent.AppendChild (el);
			}
		}