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.

Zoran HorvatRank #792 · 2.9K reputationPosted Jul 25, 2011, 3:32 AM EDT
Zoran
Suthish NairRank #92 · 22.8K reputationPosted Jul 25, 2011, 3:54 AM EDT
mahesh112 reputationPosted Jul 25, 2011, 5:15 AM EDT
Rahul #34,Street 97867687 [email protected] Mikel #45,addresstest 987678 [email protected].
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 25, 2011, 5:20 AM EDT
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
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 25, 2011, 5:21 AM EDT
Zoran
mahesh112 reputationPosted Jul 26, 2011, 12:47 AM EDT
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 26, 2011, 12:49 AM EDT
Can you paste the complete exception text here?
Zoran
mahesh112 reputationPosted Jul 26, 2011, 1:24 AM EDT
mahesh112 reputationPosted Jul 26, 2011, 1:31 AM EDT
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.