Flip,
I just had a look at my code and I saw that I'm using the XmlDocument as well. Here is what my code looks like:
public XmlDocument SQLQuery(string sqlQuery)
{
XmlDocument results = new XmlDocument();
results.LoadXml(myRepository.SQLQuery(sqlQuery));
return results;
}
Later on I convert that to an XDocument to do fun stuff with like the query:
protected object[,] MarshalXmlDocumentToArray(XmlDocument xmlElements)
{
object[,] marshalledElements;
//first check if there is data to be imported
if (xmlElements.SelectSingleNode("//Row") != null)
{
//convert to XDocument for better performance
XDocument xElements = XDocument.Load(xmlElements.CreateNavigator().ReadSubtree());
var query = from xElem in xElements.Element("EADATA").Element("Dataset_0").Element("Data").Elements("Row")
select new ExportRow
{
ID = xElem.Element("ID").Value,
Type = xElem.Element("Type").Value,
Name = xElem.Element("Name").Value,
ImportanceLevel = xElem.Element("ImportanceLevel").Value,
Author = xElem.Element("Author").Value,
Created = xElem.Element("Created").Value,
Modified = xElem.Element("Modified").Value,
Documentation = xElem.Element("Documentation").Value,
ParentName = xElem.Element("ParentName").Value,
ParentID = xElem.Element("ParentID").Value,
QualifiedName = xElem.Element("QualifiedName").Value
};
//query
List<ExportRow> rows = query.ToList();
//first add the headers
marshalledElements = new object[rows.Count, 11];
//headers now in the template excel file
//marshalledElements = this.addHeaders(marshalledElements);
//then add all rows
for (int i = 0; i < rows.Count; i++)
{
ExportRow row = rows[i];
marshalledElements[i , 0] = rows[i].ID;
marshalledElements[i , 1] = rows[i].Type;
marshalledElements[i , 2] = rows[i].Name;
marshalledElements[i , 3] = rows[i].ImportanceLevel;
marshalledElements[i , 4] = rows[i].Author;
DateTime createdDate;
if (DateTime.TryParse(rows[i].Created, out createdDate))
{
marshalledElements[i , 5] = createdDate;
}
else
{
//if the date cannot be parsed then just add the string as is
marshalledElements[i , 5] = rows[i].Created;
}
DateTime modifiedDate;
if (DateTime.TryParse(rows[i].Modified, out modifiedDate))
{
marshalledElements[i , 6] = modifiedDate;
}
else
{
//if the date cannot be parsed then just add the string as is
marshalledElements[i , 6] = rows[i].Modified;
}
marshalledElements[i , 7] = rows[i].QualifiedName;
if (rows[i].Documentation.Length < 255)
{
marshalledElements[i , 8] = rows[i].Documentation;
}
else
{
marshalledElements[i , 8] = rows[i].Documentation.Substring(0, 254);
}
marshalledElements[i , 9] = rows[i].ParentName;
marshalledElements[i , 10] = rows[i].ParentID;
}
}
else
{
//no data, just returns the array with the headers
marshalledElements = new string[1, 11];
//marshalledElements = this.addHeaders(marshalledElements);
}
return marshalledElements;
}
Geert