在下面的C#.NET代码中,我在最后一行xndNodefac["Value"].InnerText
遇到了一个问题,它给了我错误
"对象引用未设置为对象的实例"。
在XML文件中有一个节点调用"值"所有的节点都工作正常,当它来到这个"价值"节点我收到错误。
var nlfaci = xdcDocument.SelectNodes("/ns:HotelDetailRS/ns:Hotel/ns:FacilityList/ns:Feature", nsmgr);
foreach (XmlNode xndNodefac in nlfaci)
{
Label lblfac = new Label();
lblfac.Text = "Code : " + xndNodefac["Code"].InnerText + "<br />";
DivFacilityList.Controls.Add(lblfac);
Label lblfac1 = new Label();
lblfac1.Text = "Name : " + xndNodefac["Name"].InnerText + "<br />";
DivFacilityList.Controls.Add(lblfac1);
Label lblfac2 = new Label();
lblfac2.Text = "Description : " + xndNodefac["Description"].InnerText + "<br /><br />";
DivFacilityList.Controls.Add(lblfac2);
Label lblfac31 = new Label();
lblfac31.Text = "Value : " + xndNodefac["Value"].InnerText + "<br /><br />";
DivFacilityList.Controls.Add(lblfac31);
}
XML:
<HotelDetailRS xmlns="http://www.hotelbeds.com/schemas/2005/06/messages"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hotelbeds.com/schemas/2005/06/messages HotelDetailRS.xsd"
echoToken="DummyEchoToken">
<Hotel xsi:type="ProductHotel">
<FacilityList>
<Feature xsi:type="ProductFeatureSport" group="10">
<Code>20</Code>
<Name>buildingFacility</Name>
<Description>Year of construction</Description>
<Value>1985</Value>
</Feature>
<Feature xsi:type="ProductFeatureSport" group="10">
<Code>30</Code>
<Name>buildingFacility</Name>
<Description>Year of most recent renovation</Description>
<Value>2003</Value>
</Feature>
<Feature xsi:type="ProductFeatureSport" group="10">
<Code>50</Code>
<Name>buildingFacility</Name>
<Description>Number of floors (main building)</Description>
<Value>4</Value>
</Feature>
</FacilityList>
</Hotel>
</HotelDetailRS>