Example Code: Using XMLDocument to Discover Hierarchy
Applies to: SharePoint Workspace 2010 | Visual Studio 2008
The following sample code fragment iterates through all of the fields in each record in the Data element. For each record, it reads the schema name, _RecordID, _ParentID, and RecordURI directly from the XML document. These elements provide enough information to determine the hierarchy of the records.
// First create a GrooveForms2 service and a RecordQuery object
// and query for records
GrooveForms2.Forms2RecordDataSet forms2Ds = ...;
// formsDs.Data is defined as array of XML elements. If there is
// no data in the dataset, then the Data element is empty,
// thus dataset.Data will NOT be an array
if (forms2Ds.Data is Array)
{
string schemaName = "";
string recordURI = "";
double recordID = 0;
double parentID = 0;
//Walk through each of the forms record data nodes, storing record info
Array RecordArray = (Array)forms2Ds.Data;
foreach (System.Xml.XmlElement Record in RecordArray)
{
schemaName = Record.Name;
// Walk each child field element within the record
foreach (System.Xml.XmlElement Field in Record)
{
// Search for fields of interest
if (Field.Name.Equals("_RecordID"))
{
recordID = Convert.ToDouble(Field.InnerText);
}
else if (Field.Name.Equals("_ParentID"))
{
parentID = Convert.ToDouble(Field.InnerText);
// Search saved recordIDs to find parent record
}
else if (Field.Name.Equals("RecordURI"))
{
recordURI = Field.InnerText;
}
}
// Save schemaName, recordID, parentID, and recordURI.
// Compare parentID to previously read recordIDs to find parent.
// Note that parent may not be present unless you have queried
// for all records.
}
Note
This code iterates through all of the XMLElements in the Data element. If efficiency is an issue, a more efficient alternative would be to use the .NET XMLNavigator object.