Click here to Skip to main content
15,916,463 members
Home / Discussions / C#
   

C#

 
GeneralRe: Regarding Globalization Pin
vijaylumar13-Oct-09 1:12
vijaylumar13-Oct-09 1:12 
GeneralRe: Regarding Globalization Pin
stancrm13-Oct-09 1:27
stancrm13-Oct-09 1:27 
GeneralRe: Regarding Globalization Pin
vijaylumar13-Oct-09 1:41
vijaylumar13-Oct-09 1:41 
GeneralRe: Regarding Globalization Pin
stancrm13-Oct-09 1:46
stancrm13-Oct-09 1:46 
GeneralRe: Regarding Globalization Pin
vijaylumar13-Oct-09 1:59
vijaylumar13-Oct-09 1:59 
GeneralRe: Regarding Globalization Pin
stancrm13-Oct-09 2:04
stancrm13-Oct-09 2:04 
GeneralRe: Regarding Globalization Pin
benjymous13-Oct-09 3:04
benjymous13-Oct-09 3:04 
GeneralRe: Regarding Globalization Pin
Eddy Vluggen13-Oct-09 3:10
professionalEddy Vluggen13-Oct-09 3:10 
QuestionSimulation mobile users in network Pin
trungtin13-Oct-09 0:10
trungtin13-Oct-09 0:10 
QuestionxmlDocument Pin
arkiboys12-Oct-09 23:40
arkiboys12-Oct-09 23:40 
AnswerRe: xmlDocument Pin
SeMartens12-Oct-09 23:55
SeMartens12-Oct-09 23:55 
GeneralRe: xmlDocument Pin
arkiboys13-Oct-09 0:43
arkiboys13-Oct-09 0:43 
GeneralRe: xmlDocument Pin
SeMartens13-Oct-09 0:46
SeMartens13-Oct-09 0:46 
GeneralRe: xmlDocument Pin
arkiboys13-Oct-09 0:51
arkiboys13-Oct-09 0:51 
GeneralRe: xmlDocument Pin
SeMartens13-Oct-09 1:02
SeMartens13-Oct-09 1:02 
GeneralRe: xmlDocument Pin
arkiboys13-Oct-09 1:19
arkiboys13-Oct-09 1:19 
GeneralRe: xmlDocument Pin
SeMartens13-Oct-09 1:25
SeMartens13-Oct-09 1:25 
GeneralRe: xmlDocument Pin
arkiboys13-Oct-09 1:29
arkiboys13-Oct-09 1:29 
GeneralRe: xmlDocument Pin
SeMartens13-Oct-09 1:32
SeMartens13-Oct-09 1:32 
GeneralRe: xmlDocument Pin
arkiboys13-Oct-09 1:35
arkiboys13-Oct-09 1:35 
GeneralRe: xmlDocument Pin
SeMartens13-Oct-09 1:38
SeMartens13-Oct-09 1:38 
GeneralRe: xmlDocument Pin
arkiboys13-Oct-09 1:41
arkiboys13-Oct-09 1:41 
GeneralRe: xmlDocument Pin
SeMartens13-Oct-09 1:47
SeMartens13-Oct-09 1:47 
GeneralRe: xmlDocument [modified] Pin
arkiboys13-Oct-09 1:59
arkiboys13-Oct-09 1:59 
I have modified the loop so that as soon as there is an addition to the xml, then save the file and then break; this way it comes out of the loop.

Question:
I can see the xml I added is in there, so I now try to remove it as follows:
Do you see what is wrong here because i get an error on line with ????? it says object reference not set to an instance of an object.
Not that this error does not always happen. It seems I have to close the file and then re-open it to work correctly. Is this the way it should be?

Thanks

private void LoadXMLRemove()
{
XmlDocument doc = new XmlDocument();
doc.Load(strPath);

// Retrieve all .
XmlNodeList nodeList = doc.GetElementsByTagName("mapKey");

foreach (XmlNode node in nodeList)
{
//?????
string strValue = node.ChildNodes[0].Value.ToString();
//???????
if (strValue.ToLower() == "0024007")
{
if (node.NextSibling.InnerXml.Trim() == "1")
{
string strMapValue = node.NextSibling.InnerXml.Trim();

//Remove element...
Debug.WriteLine("mapKey : " + strValue + " and mapValue : " + strMapValue + " removed.");
node.RemoveChild(node.FirstChild);

doc.Save(strPath);
break;
}
}
}
}

modified on Tuesday, October 13, 2009 8:05 AM

GeneralRe: xmlDocument Pin
SeMartens13-Oct-09 2:09
SeMartens13-Oct-09 2:09 

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.