I need to load XML data into two separate datasets based on a given parameter within the XML. The data is fed back to me via a SOAP call.
Here is a very simplified XML sample:
<![CDATA[<?xml version="1.0" encoding="utf-16"?>
<ArrayOfUser xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<User>
<ID>111-111-111</ID
<Name>John Smith</Name>
<Active>0</Active>
</User>
<User>
<ID>111-111-222</ID
<Name>Bob Smith</Name>
<Active>0</Active>
</User>
<User>
<ID>111-111-333</ID
<Name>Sally Smith</Name>
<Active>1</Active>
</User>
</ArrayOfUser>]]>
Right now, I load everything into a single dataset as such:
XmlDocument UsersXmlDoc= new XmlDocument();
UsersXmlDoc.LoadXml(GetUsersResponse.Fetch_Result);
XmlReader UsersXmlReader= new XmlNodeReader(UsersXmlDoc);
DataSet ds = new DataSet();
ds.ReadXml(UsersXmlReader);
I would like instead to split that information into two datasets based on the Active property of each user so that one dataset contains active uses and the other, innactive users.
I made an example how you could do what you want. Maybe code isn’t very nice, but I think it should work. The main idea is to copy current dataset and remove active records from first and inactive records from second dataset.