Click here to Skip to main content
15,914,500 members
Home / Discussions / C#
   

C#

 
JokeRe: Invalid character while using xmldocument.load? Pin
Guffa14-Oct-08 2:51
Guffa14-Oct-08 2:51 
GeneralRe: Invalid character while using xmldocument.load? Pin
Mark Salsbery14-Oct-08 4:46
Mark Salsbery14-Oct-08 4:46 
QuestionHelp in WMI Pin
lal001213-Oct-08 20:20
lal001213-Oct-08 20:20 
AnswerRe: Help in WMI Pin
Uros Calakovic14-Oct-08 4:38
Uros Calakovic14-Oct-08 4:38 
QuestionXML as DataBase Pin
E_Gold13-Oct-08 19:58
E_Gold13-Oct-08 19:58 
AnswerRe: XML as DataBase Pin
bcozican13-Oct-08 20:10
bcozican13-Oct-08 20:10 
GeneralRe: XML as DataBase Pin
E_Gold13-Oct-08 20:33
E_Gold13-Oct-08 20:33 
GeneralRe: XML as DataBase Pin
bcozican13-Oct-08 20:56
bcozican13-Oct-08 20:56 
As Guffa has said, its easy to load the data in a datatable and then save it as xml. That will increase query performance. That will however increase your xml document size.

If you dont want to use that way, heres a really simplified example of an update to a xml file:

<?xml version="1.0"?>
<Employees>
<Employee>
<ID>1</ID>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
</Employee>
<Employee>
<ID>2</ID>
<FirstName>Peter</FirstName>
<LastName>Pan</LastName>
</Employee>
</Employees>



string xmlFilePath = @"C:\Employees.xml";
int EmployeeIdToUpdate = 2;
string NewEmployeeLastName = "Panne";
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(xmlFilePath);

System.Xml.XmlNode eNode = doc.SelectSingleNode("Employees");
for (int i = 0; i < eNode.ChildNodes.Count; i++)
{
System.Xml.XmlNode employeeNode = eNode.ChildNodes[i];

int ID = int.Parse(employeeNode.SelectSingleNode("ID").InnerText);
if (ID == EmployeeIdToUpdate)
{
//Perform action
employeeNode.SelectSingleNode("LastName").InnerText = NewEmployeeLastName;
}
}
doc.Save(xmlFilePath);


Hope this helps.
AnswerRe: XML as DataBase Pin
Guffa13-Oct-08 20:38
Guffa13-Oct-08 20:38 
GeneralRe: XML as DataBase Pin
E_Gold13-Oct-08 22:15
E_Gold13-Oct-08 22:15 
AnswerRe: XML as DataBase Pin
Guffa13-Oct-08 22:45
Guffa13-Oct-08 22:45 
AnswerRe: XML as DataBase Pin
N a v a n e e t h13-Oct-08 20:41
N a v a n e e t h13-Oct-08 20:41 
QuestionShow Control out of the Window Pin
softwarejaeger13-Oct-08 19:44
softwarejaeger13-Oct-08 19:44 
AnswerRe: Show Control out of the Window Pin
leppie13-Oct-08 22:17
leppie13-Oct-08 22:17 
GeneralRe: Show Control out of the Window [modified] Pin
softwarejaeger14-Oct-08 2:32
softwarejaeger14-Oct-08 2:32 
QuestionHow to add Plugin in IE ? Pin
bishwajeet13-Oct-08 19:42
bishwajeet13-Oct-08 19:42 
QuestionGridview by using TemplateField? Pin
my_amrizal13-Oct-08 16:44
my_amrizal13-Oct-08 16:44 
QuestionSet Seperate Background Images of Dual Monitors Pin
aj.esler13-Oct-08 14:13
aj.esler13-Oct-08 14:13 
AnswerRe: Set Seperate Background Images of Dual Monitors Pin
Jakob Olsen14-Oct-08 1:00
Jakob Olsen14-Oct-08 1:00 
GeneralRe: Set Seperate Background Images of Dual Monitors Pin
aj.esler14-Oct-08 11:12
aj.esler14-Oct-08 11:12 
GeneralRe: Set Seperate Background Images of Dual Monitors Pin
Jakob Olsen14-Oct-08 21:10
Jakob Olsen14-Oct-08 21:10 
QuestionExternal sorting Pin
Diamonddrake13-Oct-08 13:37
Diamonddrake13-Oct-08 13:37 
AnswerRe: External sorting Pin
Simon P Stevens13-Oct-08 22:51
Simon P Stevens13-Oct-08 22:51 
GeneralRe: External sorting Pin
Diamonddrake14-Oct-08 10:08
Diamonddrake14-Oct-08 10:08 
GeneralRe: External sorting Pin
Simon P Stevens14-Oct-08 11:15
Simon P Stevens14-Oct-08 11:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.