Good Evening StackOverFlowers,
I have recently starting coding in XML via Visual Studio 2010. I have come across what seems to be a simple solution, yet the solution escapes me. I get an error for an Object Reference not set, but I don't see what I haven't set. (error here: https://i.sstatic.net/CDZgG.png )
My codebehind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
public partial class _Default : System.Web.UI.Page
{
int intDVDID;
XmlDocument myXmlDocument = new XmlDocument();
XmlNode rootNode;
XmlNode selectedDVD;
public void Page_Load(object Src, EventArgs E)
{
intDVDID = Convert.ToInt32(Request.QueryString["id"]);
myXmlDocument.Load(Request.PhysicalApplicationPath + @"dvd.xml");
rootNode = myXmlDocument.DocumentElement;
selectedDVD = rootNode.ChildNodes[intDVDID - 1];
if (!Page.IsPostBack)
{
rootNode.RemoveChild(selectedDVD);
myXmlDocument.Save(Request.PhysicalApplicationPath + @"dvd.xml");
lblMessage.Text = "You have successfully deleted the DVD";
}
}
}
Is it just a matter of saying:
int intDVDID = new intDVDID
I know by reading this you're all going to want to pull your hair out at my inexperience and lack of understanding how to solve this, but I appreciate your time and your patience just looking.
Best regards, Laura :)
Edit: Here is my XML:
<?xml version="1.0" encoding="utf-8" ?>
<!-- This XML document describes a DVD library -->
<library>
<DVD id="1">
<title>Breakfast at Tiffany's</title>
<format>Movie</format>
<genre>Classic</genre>
</DVD>
<DVD id="2">
<title>Contact</title>
<format>Movie</format>
<genre>Science fiction</genre>
</DVD>
<DVD id="3">
<title>Little Britain</title>
<format>TV Series</format>
<genre>Comedy</genre>
</DVD>
</library>
dvd.xmllook like?idwhen you get this error?