Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hi
 
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 :
 
<AvokaSmartForm>
    <FormData>
        <CurrentPage>1</CurrentPage>
        <CustomerDetails>
            <CIDN/>
            <CompanyDetails>
                <ABN>62091152573</ABN>
                <ACN>091152573</ACN>
                <ABNACN/>
                <CompanyName>RSJ TRADING PTY LTD T/AS BM GU</CompanyName>
                <BusinessName>RSJ TRADING PTY LTD T/AS BM GU</BusinessName>
                <Address>
 
                    <Address1>700 WATERDALE RD</Address1>
                    <Address2/>
                    <Suburb>BANDURA</Suburb>
                    <State>VIC</State>
                    <Postcode>3083</Postcode>
                </Address>
 
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
Edited 28-Feb-13 2:08am
v4
Comments
phil.o at 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 at 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
good
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.
  Permalink  
v2
Comments
Orcun Iyigun at 28-Feb-13 8:48am
   
5ed.

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

  Print Answers RSS
0 OriginalGriff 392
1 CPallini 365
2 Sergey Alexandrovich Kryukov 348
3 BillWoodruff 264
4 George Jonsson 255
0 OriginalGriff 5,095
1 CPallini 4,285
2 Sergey Alexandrovich Kryukov 3,767
3 George Jonsson 2,941
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 28 Feb 2013
Copyright © CodeProject, 1999-2014
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