I want to append tag and attribute values to the existing xml file.Here is my code
Strpath = AppDomain.CurrentDomain.BaseDirectory.ToString & "data.xml"
Dim doc As XDocument = XDocument.Load(Strpath)
Dim xmlnode As XElement = doc.
'Dim xmleleattr As XElement
Dim xmleleattr As XElement = _
<%= David %>
<%= Royal street %>
<%= 98767896%>
<%= [email protected]%>
xmlnode.Add(New XElement(xmleleattr)) // in this line i,m getting an error that object reference not set to an instance of an object.
xmlnode.Save(Strpath)
Thanks in advance.
maheshPosted Jul 26, 2011, 5:31 AM
Dim xmldoc As New XmlDocument Strpath = AppDomain.CurrentDomain.BaseDirectory & "data.xml" xmldoc.Load(Strpath)
Dim xmlel As XmlElement xmlel = xmldoc.CreateElement("Name") xmlel.InnerText = "David" xmldoc.DocumentElement.AppendChild(xmlel)
xmlel = Nothing
xmlel = xmldoc.CreateElement("Address")
xmlel.InnerText = "#34,street"
xmldoc.DocumentElement.AppendChild(xmlel)
xmlel = xmldoc.CreateElement("PhoneNumber")
xmlel.InnerText = "8979"
xmldoc.DocumentElement.AppendChild(xmlel)
xmlel = Nothing
xmlel = xmldoc.CreateElement("Email")
xmlel.InnerText = "gfhg.com"
xmldoc.DocumentElement.AppendChild(xmlel)
xmlel = Nothing
xmldoc.Save(Strpath)
thanks for ur kind response.
maheshPosted Jul 26, 2011, 5:24 AM
Zoran HorvatPosted Jul 26, 2011, 4:49 AM
Can you paste the complete exception text here?
Zoran
maheshPosted Jul 26, 2011, 4:47 AM
Zoran HorvatPosted Jul 25, 2011, 9:21 AM
Zoran
Zoran HorvatPosted Jul 25, 2011, 9:20 AM
Dim xmlnode As XElement = doc.
That will try to execute physical path as XPath, which probably has nothing to do with XML document's contents. That's why xmlnode remains null (Nothing) and consequently you have object reference not set to an instance of an object.
Zoran
maheshPosted Jul 25, 2011, 9:15 AM
Rahul #34,Street 97867687 [email protected] Mikel #45,addresstest 987678 [email protected].
Suthish NairPosted Jul 25, 2011, 7:54 AM
Zoran HorvatPosted Jul 25, 2011, 7:32 AM
Zoran