how to insert the data into xml file using asp.net with vb.net [modified]
-
hello everybody. i want to insert the data into xmlfile.how it possible. i developed code for this .but i dont know whether it is correct or not. Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click ' Create xml dom Dim XMLDom As New XmlDocument() 'this xml file is already i created. XMLDom.Load("D:\XMLFILE1.xml") 'Selecting the main node Dim newXMLNode As XmlNode = XMLDom.SelectSingleNode("persons") '''''''get the node where i want to insert the data Dim childNode As XmlNode = XMLDom.CreateNode(XmlNodeType.Element, "p", "") ''''''''In the below step "p" is my node name and "sree" is my data to insert Dim newAttribute As XmlAttribute = XMLDom.CreateAttribute("p", "sree", "") childNode.Attributes.Append(newAttribute) newXMLNode.AppendChild(childNode) end sub when i run this code error occured i.e Object reference not set to an instance of an object. this error is occured in newXMLNode.AppendChild(childNode)
modified on Thursday, February 25, 2010 2:09 AM
-
hello everybody. i want to insert the data into xmlfile.how it possible. i developed code for this .but i dont know whether it is correct or not. Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click ' Create xml dom Dim XMLDom As New XmlDocument() 'this xml file is already i created. XMLDom.Load("D:\XMLFILE1.xml") 'Selecting the main node Dim newXMLNode As XmlNode = XMLDom.SelectSingleNode("persons") '''''''get the node where i want to insert the data Dim childNode As XmlNode = XMLDom.CreateNode(XmlNodeType.Element, "p", "") ''''''''In the below step "p" is my node name and "sree" is my data to insert Dim newAttribute As XmlAttribute = XMLDom.CreateAttribute("p", "sree", "") childNode.Attributes.Append(newAttribute) newXMLNode.AppendChild(childNode) end sub when i run this code error occured i.e Object reference not set to an instance of an object. this error is occured in newXMLNode.AppendChild(childNode)
modified on Thursday, February 25, 2010 2:09 AM
Hi, Check "newXMLNode" is null or not. Thanks Prosanta