以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 未将对象引用设置到对象的实例。 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=78656) |
||||
-- 作者:gryy -- 发布时间:2015/12/14 15:39:00 -- 未将对象引用设置到对象的实例。 想在已有的xml文件中添加节,提示“未将对象引用设置到对象的实例”,请教下哪里出了问题 Dim xmlDoc As New System.XML.XmlDocument xmlDoc.Load("d:\\201510020.xml") Dim root As System.XML.XmlNode = xmldoc.SelectSingleNode("DataField") Dim xel As System.XML.xmlelement = xmldoc.CreateElement("Data") xel.SetAttribute("Code","889824100000") xel.SetAttribute("CorpOrderID","201510020 ") xel.SetAttribute("Actor","") xel.SetAttribute("ActDate","2015-10-22") xel.SetAttribute("CorpProductID","") xel.SetAttribute("CorpBatchNo","") xel.SetAttribute("ProduceDate","2015-08-28") xel.SetAttribute("ToCorpID","") root.appendchild(xel) xmldoc.save("d:\\201510020.xml")
[此贴子已经被作者于2015/12/14 16:12:48编辑过]
|
||||
-- 作者:大红袍 -- 发布时间:2015/12/14 15:44:00 -- 应该是没找到 DataField 节点。
文件发上来测试。 |
||||
-- 作者:gryy -- 发布时间:2015/12/14 16:13:00 --
|
||||
-- 作者:大红袍 -- 发布时间:2015/12/14 16:23:00 -- Dim xmlDoc As New System.XML.XmlDocument xmlDoc.Load("d:\\201510020.xml") Dim root As System.XML.XmlNode = xmldoc.SelectSingleNode("Document/Events/Event/DataField") msgbox(root Is Nothing) Dim xel As System.XML.xmlelement = xmldoc.CreateElement("Data") xel.SetAttribute("Code","889824100000") xel.SetAttribute("CorpOrderID","201510020 ") xel.SetAttribute("Actor","") xel.SetAttribute("ActDate","2015-10-22") xel.SetAttribute("CorpProductID","") xel.SetAttribute("CorpBatchNo","") xel.SetAttribute("ProduceDate","2015-08-28") xel.SetAttribute("ToCorpID","") root.appendchild(xel) xmldoc.save("d:\\201510020.xml") |