读取XML数据时出现对象引用错误 [英] Object Ref error while reading XML Data

查看:60
本文介绍了读取XML数据时出现对象引用错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想在标签上显示XML数据。我有xml文件Form Data.xml。我想显示Address1。我写了以下代码

相同。但是当我运行时出现错误.. 对象引用未设置为对象的实例。 on

Label1.Text = xmldoc.SelectSingleNode("/FormData/Address/Address1").FirstChild.Value;







Form Data.xml:






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>





代码:检查路径/ FormData / Address / 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 ..

推荐答案

所以你的 xmldoc 变量为空。

请在您正在修改此变量的行上放置一个断点,在调试模式(F5)中确定您的解决方案,看看会发生什么。



我的猜测是你写的XML路径不正确。
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.


这篇关于读取XML数据时出现对象引用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆