wcmcalister@gmail.com wrote:
Quote:
|
Can someone show me how to match the data into the XmlNode object?
|
Use XPath to find the right Table element, then use CreateElement to
create a new AccountNum element, then use AppendChild to add the newly
created element. When finished, save the XML document:
XmlDocument doc = new XmlDocument();
doc.Load(@"..\..\XMLFile1.xml");
List<Dataaccounts = new List<Data>();
Data account = new Data();
account.ID = 123;
account.AccountNumber = 987654321;
accounts.Add(account);
account = new Data();
account.ID = 124;
account.AccountNumber = 987654322;
accounts.Add(account);
foreach (Data data in accounts)
{
XmlNode table =
doc.SelectSingleNode(string.Format("/NewDataSet/Table[ID = {0}]", data.ID));
if (table != null)
{
XmlElement accountNum =
doc.CreateElement("AccountNum");
accountNum.InnerText = data.AccountNumber.ToString();
table.AppendChild(accountNum);
}
}
//saving to Console.Out for testing, could save to file or
stream instead
doc.Save(Console.Out);
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/