Click here to Skip to main content
15,915,501 members
Home / Discussions / C#
   

C#

 
GeneralRe: Datagridview cell painting Pin
Dan Neely30-Apr-09 8:41
Dan Neely30-Apr-09 8:41 
GeneralRe: Datagridview cell painting Pin
Jake Myers1-May-09 4:20
Jake Myers1-May-09 4:20 
GeneralRe: Datagridview cell painting Pin
Dan Neely1-May-09 4:37
Dan Neely1-May-09 4:37 
GeneralRe: Datagridview cell painting [modified] Pin
Jake Myers1-May-09 5:06
Jake Myers1-May-09 5:06 
QuestionUnlocking account in AD Pin
Jacob Dixon18-Mar-09 7:53
Jacob Dixon18-Mar-09 7:53 
QuestionHelp understanding C# sockets Pin
John Joger18-Mar-09 7:47
John Joger18-Mar-09 7:47 
AnswerRe: Help understanding C# sockets Pin
John Joger21-Mar-09 16:23
John Joger21-Mar-09 16:23 
QuestionXML root element changes after manipulating XML file. Need help. Pin
shira_me18-Mar-09 7:39
shira_me18-Mar-09 7:39 
I've written code (in C#) to read an existing XML file and to update one of its nodes (not the root node !!!).
This code compiles and the appropriate data changes occur but...I noticed that the root element also changes its structure and, for some reason, contains garbage. Is there any changes I need to do in my code for it to preserve the XML file original structure?
Here is the code:
=================
private void AppendXMLDocument()
{
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.PreserveWhitespace = true;
xmlDoc.Load(sXMLFile);

XmlNodeList nList = xmlDoc.GetElementsByTagName(sTag);
//I've changed the data for confidentiality reasons
string sData = "xxxxx";

foreach (XmlNode node in nList)
{
//Append node with new data
node.InnerText = sData;

}


XmlTextWriter tw = new XmlTextWriter(sXMLFile, Encoding.UTF8);
tw.Formatting = Formatting.Indented; //this preserves indentation
xmlDoc.PreserveWhitespace = true;
xmlDoc.Save(tw);
tw.Close();


}
catch (Exception e)
{
Console.Write(e.Message);
//freeze Console to show error
Console.ReadLine();

}
}
}
The changes to the XML root element are as follows:
--------------------------------------------------
original root element:
---------------------
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84
http://www.google.com/schemas/sitemap/0.84/sitemap.xsd>

after update of data (which, again, does not include the root element what-so-ever):
------------------------------------------------------------------------------------

http://www.google.com/schemas/sitemap/0.84/sitemap.xsd>

Thanx, shira
AnswerRe: XML root element changes after manipulating XML file. Need help. Pin
bgato2k618-Mar-09 11:02
bgato2k618-Mar-09 11:02 
QuestionHow old is F# ? Pin
Mohammad Dayyan18-Mar-09 7:29
Mohammad Dayyan18-Mar-09 7:29 
AnswerRe: How old is F# ? Pin
Yusuf18-Mar-09 7:35
Yusuf18-Mar-09 7:35 
GeneralRe: How old is F# ? Pin
Mohammad Dayyan18-Mar-09 8:19
Mohammad Dayyan18-Mar-09 8:19 
GeneralRe: How old is F# ? Pin
Judah Gabriel Himango18-Mar-09 8:55
sponsorJudah Gabriel Himango18-Mar-09 8:55 
AnswerRe: How old is F# ? Pin
musefan18-Mar-09 7:35
musefan18-Mar-09 7:35 
GeneralRe: How old is F# ? Pin
Ravadre18-Mar-09 7:50
Ravadre18-Mar-09 7:50 
GeneralRe: How old is F# ? Pin
0x3c018-Mar-09 7:57
0x3c018-Mar-09 7:57 
GeneralRe: How old is F# ? Pin
Ravadre18-Mar-09 8:07
Ravadre18-Mar-09 8:07 
GeneralRe: How old is F# ? Pin
0x3c018-Mar-09 8:19
0x3c018-Mar-09 8:19 
GeneralRe: How old is F# ? Pin
Mohammad Dayyan18-Mar-09 8:26
Mohammad Dayyan18-Mar-09 8:26 
GeneralRe: How old is F# ? Pin
0x3c018-Mar-09 8:38
0x3c018-Mar-09 8:38 
GeneralRe: How old is F# ? Pin
Ravadre18-Mar-09 8:46
Ravadre18-Mar-09 8:46 
GeneralRe: How old is F# ? Pin
0x3c018-Mar-09 8:55
0x3c018-Mar-09 8:55 
GeneralRe: How old is F# ? Pin
Ravadre18-Mar-09 9:25
Ravadre18-Mar-09 9:25 
GeneralRe: How old is F# ? Pin
0x3c018-Mar-09 9:34
0x3c018-Mar-09 9:34 
GeneralRe: How old is F# ? Pin
Ravadre18-Mar-09 9:37
Ravadre18-Mar-09 9:37 

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.