Click here to Skip to main content
15,895,011 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: xmlDocument Pin
arkiboys13-Oct-09 2:16
arkiboys13-Oct-09 2:16 
GeneralRe: xmlDocument Pin
arkiboys13-Oct-09 4:23
arkiboys13-Oct-09 4:23 
GeneralRe: xmlDocument Pin
SeMartens13-Oct-09 4:27
SeMartens13-Oct-09 4:27 
GeneralRe: xmlDocument Pin
arkiboys13-Oct-09 5:00
arkiboys13-Oct-09 5:00 
AnswerRe: xmlDocument Pin
Mirko198012-Oct-09 23:56
Mirko198012-Oct-09 23:56 
Questionprinting 2 document to same file/ preview Pin
samy10012-Oct-09 23:39
samy10012-Oct-09 23:39 
AnswerRe: printing 2 document to same file/ preview Pin
Henry Minute13-Oct-09 1:35
Henry Minute13-Oct-09 1:35 
GeneralRe: printing 2 document to same file/ preview Pin
samy10013-Oct-09 2:12
samy10013-Oct-09 2:12 
GeneralRe: printing 2 document to same file/ preview Pin
Henry Minute13-Oct-09 3:04
Henry Minute13-Oct-09 3:04 
Questionchange scrollbar maxvalue in treeview Pin
Deabdy2112-Oct-09 23:19
Deabdy2112-Oct-09 23:19 
AnswerRe: change scrollbar maxvalue in treeview Pin
Calla13-Oct-09 0:05
Calla13-Oct-09 0:05 
Questionwhat is ObjectSender and EventArgs in Windows Form Pin
ldsdbomber12-Oct-09 23:07
ldsdbomber12-Oct-09 23:07 
AnswerRe: what is ObjectSender and EventArgs in Windows Form Pin
Mirko198013-Oct-09 0:05
Mirko198013-Oct-09 0:05 
AnswerRe: what is ObjectSender and EventArgs in Windows Form Pin
Luc Pattyn13-Oct-09 3:03
sitebuilderLuc Pattyn13-Oct-09 3:03 
GeneralRe: what is ObjectSender and EventArgs in Windows Form Pin
ldsdbomber13-Oct-09 3:49
ldsdbomber13-Oct-09 3:49 
GeneralRe: what is ObjectSender and EventArgs in Windows Form Pin
Luc Pattyn13-Oct-09 4:11
sitebuilderLuc Pattyn13-Oct-09 4:11 

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.