Click here to Skip to main content
13,449,425 members (38,078 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I want to show XML data on labels.I have xml File "Form Data.xml" .I want to show Address1 .I wrote following code
for same. But When I run I got error..Object reference not set to an instance of an object. on
Label1.Text = xmldoc.SelectSingleNode("/FormData/Address/Address1").FirstChild.Value;

Form Data.xml :

                <CompanyName>RSJ TRADING PTY LTD T/AS BM GU</CompanyName>
                <BusinessName>RSJ TRADING PTY LTD T/AS BM GU</BusinessName>

                    <Address1>700 WATERDALE RD</Address1>

Code : Check Path "/FormData/Address/Address1" is correct as per above File or not.
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(@"C:\inetpub\wwwroot\Form Data.xml");
Label1.Text = xmldoc.SelectSingleNode("/FormData/Address/Address1").FirstChild.Value;

Please Tell me ..
Posted 28-Feb-13 1:57am
Updated 28-Feb-13 2:08am
phil.o 28-Feb-13 8:01am
Object reference not set to an instance of an object
On which line does this exception occur ? And please post the corresponding line.
Rectus 28-Feb-13 8:10am
Object reference not set to an instance of an object on Label1.Text = xmldoc.SelectSingleNode("/FormData/Address/Address1").FirstChild.Value;

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

So your xmldoc variable is null.
Please put a breakpoint on the line your are instanciating this variable, lauch your solution in debug mode (F5), and see what happens.

My guess is that the XML path you wrote is incorrect.
Orcun Iyigun 28-Feb-13 8:48am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02-2016 | 2.8.180318.3 | Last Updated 28 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100