C# Programming
10-13-2009, 11:41 PM
Hi,
Assuming I have an xml file which looks something like:
1234
uyt
...
...
654322
xyz
...
...
...
...
The code below retrieves the values for
ElementName>654322 and
xyz as shown:
private void ModifyXML()
{
XmlDocument doc = new XmlDocument();
doc.Load(strPath);
// Retrieve all prices.
XmlNodeList nodeList = doc.GetElementsByTagName("ElementName");
foreach (XmlNode node in nodeList)
{
string strValue = node.ChildNodes[0].Value.ToString();
if (strValue.ToLower() == "654322")
{
ListBox1.Items.Add(node.OuterXml);
ListBox1.Items.Add(node.NextSibling.OuterXml);
ListBox1.Items.Add("");
//Console.WriteLine(node.ChildNodes[0].Value);
//Console.WriteLine(node.NextSibling.InnerXml);
}
}
}
Question:
Please note that I do not want to use xpath or linq or database. Just the xmlDocument for business reasons
Using this code below, how can I add a column element i.e.
Thanks
newValue
newdata
OR
delete one of the above column elements i.e. to remove:
654322
xyz
Assuming I have an xml file which looks something like:
1234
uyt
...
...
654322
xyz
...
...
...
...
The code below retrieves the values for
ElementName>654322 and
xyz as shown:
private void ModifyXML()
{
XmlDocument doc = new XmlDocument();
doc.Load(strPath);
// Retrieve all prices.
XmlNodeList nodeList = doc.GetElementsByTagName("ElementName");
foreach (XmlNode node in nodeList)
{
string strValue = node.ChildNodes[0].Value.ToString();
if (strValue.ToLower() == "654322")
{
ListBox1.Items.Add(node.OuterXml);
ListBox1.Items.Add(node.NextSibling.OuterXml);
ListBox1.Items.Add("");
//Console.WriteLine(node.ChildNodes[0].Value);
//Console.WriteLine(node.NextSibling.InnerXml);
}
}
}
Question:
Please note that I do not want to use xpath or linq or database. Just the xmlDocument for business reasons
Using this code below, how can I add a column element i.e.
Thanks
newValue
newdata
OR
delete one of the above column elements i.e. to remove:
654322
xyz