For example:
string Address1 = EmpNode.SelectSingleNode( "Address1/AddressNames/AddressName" )?.InnerText;
string Address2 = EmpNode.SelectSingleNode( "Address2/AddressNames/AddressName" )?.InnerText;
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am reading XML file which contains large data. The element attributes contains many child fields.
I Just want to know, how to get the specific child fields from the XMLNode list.
below is my sample code and data.
<Employee EmpId="23817348328">
<Address1>
<AddressNames>
<AddressName>USA-STATE1</AddressName>
</AddressNames>
<AddressType>ADDRESS1</AddressType>
</Address1>
<Address2>
<AddressNames>
<AddressName>CANADA-STATE9</AddressName>
</AddressNames>
<AddressType>ADDRESS2</AddressType>
</Address2>
</Employee>
i want to get Address1 and Address2 values from the XMLNodes.
output for Address1 ==> USA-STATE1
output for Address2 ==> CANADA-STATE9
below is my code for xml nodes.
XmlNodeList EmpNodes = xmlDoc.SelectNodes("//Employee");
foreach (XmlNode EmpNode in EmpNodes)
{
long EmpId = long.Parse(EmpNode.Attributes["EmpId"].Value);
string Address1 = ????
string Address2 = ????
}
shall i consider string Address1 = documentNode.FirstChild.FirstChild.FirstChild.InnerText;
is that correct way to get address value...?
For example:
string Address1 = EmpNode.SelectSingleNode( "Address1/AddressNames/AddressName" )?.InnerText;
string Address2 = EmpNode.SelectSingleNode( "Address2/AddressNames/AddressName" )?.InnerText;