EDN Admin
Well-known member
I would like to use LINQ to XML exclusively, but I cant seem to figure out how to use XML Namespaces with LINQ to XML. My code is below, I take the output from the GetListItems, and convert it to an XMLDocument so I can use XPath. But I would like to translate
this to the LINQ way of working with XML. Its the highly structured XML name spaces that LINQ is having issues with.
private void getLists()
{
string _targetList = Properties.Settings.Default.ListName_Capital.ToString();
string _sharePointURL = BayerSharePointMigrator.General.getSharePointURL();
web_service.ListsSoapClient _listService = SharePointService.General.getNewListClient();
XElement ndQuery = new XElement("Query", "<Where><Eq><FieldRef Name=hProjectStatus/><Value Type=Text>Approved</Value></Eq></Where>");
XElement ndViewFields = new XElement("ViewFields", "<FieldRef Name=ID/><FieldRef Name=GUID/><FieldRef Name=Title/><FieldRef Name=hProjectStatus/>");
XElement ndQueryOptions = new XElement("QueryOptions", "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns><DateInUtc>TRUE</DateInUtc>");
try
{
XElement xListItems = _listService.GetListItems(_TargetList, null, ndQuery, ndViewFields, null, ndQueryOptions, null);
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(xListItems.ToString());
XmlNamespaceManager nm = new System.Xml.XmlNamespaceManager(xDoc.NameTable);
nm.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
nm.AddNamespace("z", "#RowsetSchema");
nm.AddNamespace("rootNS", "http://schemas.microsoft.com/sharepoint/soap/");
System.Xml.XmlNodeList nl = xDoc.SelectNodes("/rootNS:listitems/rs:data/z:row", nm);
_ProjectList = new string[nl.Count];
int x = 0;
foreach (XmlNode listItem in nl)
{
_ProjectList.SetValue(listItem.Attributes["ows_Title"].Value.ToString(), x);
x++;
}
this.DialogResult = DialogResult.OK;
}
catch (Exception ex)
{
this.DialogResult = DialogResult.Abort;
_ProcessResult = ex.Message.ToString();
}
}
Any clues, pointers or BBQ recipes are appreciated.
<hr class="sig -- Anthony Baratta
View the full article
this to the LINQ way of working with XML. Its the highly structured XML name spaces that LINQ is having issues with.
private void getLists()
{
string _targetList = Properties.Settings.Default.ListName_Capital.ToString();
string _sharePointURL = BayerSharePointMigrator.General.getSharePointURL();
web_service.ListsSoapClient _listService = SharePointService.General.getNewListClient();
XElement ndQuery = new XElement("Query", "<Where><Eq><FieldRef Name=hProjectStatus/><Value Type=Text>Approved</Value></Eq></Where>");
XElement ndViewFields = new XElement("ViewFields", "<FieldRef Name=ID/><FieldRef Name=GUID/><FieldRef Name=Title/><FieldRef Name=hProjectStatus/>");
XElement ndQueryOptions = new XElement("QueryOptions", "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns><DateInUtc>TRUE</DateInUtc>");
try
{
XElement xListItems = _listService.GetListItems(_TargetList, null, ndQuery, ndViewFields, null, ndQueryOptions, null);
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(xListItems.ToString());
XmlNamespaceManager nm = new System.Xml.XmlNamespaceManager(xDoc.NameTable);
nm.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
nm.AddNamespace("z", "#RowsetSchema");
nm.AddNamespace("rootNS", "http://schemas.microsoft.com/sharepoint/soap/");
System.Xml.XmlNodeList nl = xDoc.SelectNodes("/rootNS:listitems/rs:data/z:row", nm);
_ProjectList = new string[nl.Count];
int x = 0;
foreach (XmlNode listItem in nl)
{
_ProjectList.SetValue(listItem.Attributes["ows_Title"].Value.ToString(), x);
x++;
}
this.DialogResult = DialogResult.OK;
}
catch (Exception ex)
{
this.DialogResult = DialogResult.Abort;
_ProcessResult = ex.Message.ToString();
}
}
Any clues, pointers or BBQ recipes are appreciated.
<hr class="sig -- Anthony Baratta
View the full article