写入XML节点 [英] writing to a XML node
本文介绍了写入XML节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello,
I am trying to add a new node to a xml file. The code that I wrote works fine when there is a node exists but if not it throws an error of "object referance not set to an instance of an object." Basiccaly code copies a node and then writes data to the child nodes of the parent node. When I debug this code;
XmlNode credentialsnodedetails = xmlDocument.SelectNodes("/Credentials/Credential")[0];
XmlNode newnode = credentialsnodedetails.CloneNode(true);
I see that "credentialsnodedetails" value is NULL. I think because it is null I am having the problem. What should do programatically to avoid it?
推荐答案
您好,
您看过try {} catch {}吗?
Hello,
Have you look at try{} catch{}?
try{
//your code here...
}
catch{
//catch exception here... and do what ever you want with it.
}
网上有很多异常处理文章和示例.
There are plenty of exception handling articles and example on the web.
这篇关于写入XML节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文