I have one XmlNodeList, I want to create two XmlNodeList out of this. I will be checking for some tag inside each item in List, on the basis of that tag presence I will be adding them to one of the list which I have defined.
I was trying to add the list but I did not any method to add the particular item to a new XmlNodeList which is null in the start . Please help out. What I am missing here.
I have tried List<XmlNode> , it is throwing error System.ArgumentNullException: 'Value cannot be null. Parameter name: source'
class Program
{
static void Main(string[] args)
{
//Import XMl
// XmlNode list as name NEW
foreach(XmlNode emp in NEW)
{
if (emp != null)
{
AddNewList(emp);
}
}
}
public static void AddNewList(XmlNode emp)
{
//Checking for some tag
if(tag!=null)
{
// It is throwing error
currentList.Append(emp);
}
}
public XmlNodeList currentList = null;
public XmlNodeList previousList = null;
}
}
The only way to have items in
XmlNodeListis to run selection query on XmlNode. There is no other way to constructXmlNodeList.So the only option to "split" XmlNodeList in two XmlNodeList is to run separate XPath queries with opposite conditions that will select nodes into separate lists.
Note that
XmlNodeListis notList<XmlNode>despite very similar name - adding toList<XmlNode>is indeed possible.