Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
SQL
Label1.Text = xmldoc.SelectSingleNode("/FormData/Address/Address1").FirstChild.Value;



Form Data.xml :

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.
C#
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
Updated 28-Feb-13 2:08am
v4
Comments
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.
[no name] 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

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.
 
Share this answer
 
v2
Comments
Orcun Iyigun 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900