I am reading the term store metadata information from /_vti_bin/TaxonomyClientService.asmx?WSDL webservice to fill the infopath dropdown list.But I am getting the "Object reference not set to an instance of an object" error at the "newNode = nav.Clone();" line. Here is my code:
XPathNavigator mainNav = this.MainDataSource.CreateNavigator();
cleanupDropdown(mainNav, "/my:myFields/my:Countries");
XPathNavigator termSetNav = this.DataSources["GetCountries"].CreateNavigator();
string xPath = "/dfs:myFields/dfs:dataFields/tns:GetChildTermsInTermSetResponse/tns:GetChildTermsInTermSetResult";
XPathNavigator nodeNav = termSetNav.SelectSingleNode(xPath, this.NamespaceManager);
string resultXML = nodeNav.Value.ToString();
XmlDocument termSetXML = new XmlDocument();
termSetXML.LoadXml(resultXML);
XmlNodeList terms = termSetXML.GetElementsByTagName("T");
XPathNavigator nav = this.CreateNavigator().
SelectSingleNode("/my:myFields/my:Countries", this.NamespaceManager);// Note: "/my:myFields/my:Countries" => Group Countries
foreach (XmlNode term in terms)
{
XmlNode v = term.SelectSingleNode("LS/TL");
string termValue = v.Attributes["a32"].Value;
string termGuid = term.Attributes["a9"].Value;
XPathNavigator newNode = null;
newNode = nav.Clone(); //Object reference not set to an instance of an object.
newNode.SelectSingleNode("/my:myFields/my:Countries/my:Displayname",
this.NamespaceManager).SetValue(termValue);
newNode.SelectSingleNode("/my:myFields/my:Countries/my:Value",
this.NamespaceManager).SetValue(termValue);
nav.InsertAfter(newNode);
newNode = null;
}
nav.DeleteSelf();
nav = null;