I am using C # , and I need to convert an XML list to an array so that it can be sent via WCF and that data can be displayed in the web client.
Of the following arrangement I just need to keep Name
and Url
.
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<Cameras>
<Camera Name="Camera1" Url="Camera1" Width="600" Height="800" />
<Camera Name="Camera2" Url="Camera2" Width="600" Height="800" />
</Cameras>
</Configuration>
I was dealing with this code ...
XmlDocument xml = new XmlDocument();
xml.Load(
Path.Combine(
Path.GetDirectoryName(
typeof(ConfigListenerSecondary).Assembly.Location
), configFile
)
);
XmlNodeList xnList = xml.SelectNodes("//Camera");
foreach (XmlNode xn in xnList)
{
string Name = xn["Name"].InnerText;
string Url = xn["Url"].InnerText;
Console.WriteLine(Name, Url);
}
... but it displays the following error:
System.NullReferenceException: 'Object reference not set to an instance of an object.'