Hi all,
I just picked up XML and trying to figure out on CSharp.
Would like some pointers here.
E.g of my XML file
<configfile avi-in-btw="1" gif-in-btw="1">
<keyframecount num="2">
<backgroundfile
num="1">C:\work\dev\JCacaniServer\BackgroundDir\di sney_bg1.jpg</backgroundfile>
<backgroundfile
num="2">C:\work\dev\JCacaniServer\BackgroundDir\di sney_bg2.jpg</backgroundfile>
</keyframecount>
<textcount num="0"/>
</configfile>
XmlNodeList elements = xmlDocument.SelectNodes("//configfile");
foreach (XmlElement element in elements)
{
Console.WriteLine("avi-in-btw: " +
element.GetAttribute("avi-in-btw"));
Console.WriteLine("gif-in-btw: " +
element.GetAttribute("gif-in-btw"));
}
Since there would only be one element <configfile>, i would like to
just get the single element <configfileand get the attribute in it.
How do i go about doing it?
elements =
xmlDocument.SelectNodes("//configfile/keyframecount/backgroundfile");
foreach (XmlElement element in elements)
{
Console.Write("num: " + element.GetAttribute("num") +"
");
if (element.Value == null)
Console.WriteLine("No background file");
else
Console.WriteLine(element.Value);
}
i would like to get the text value for the element <backgroundfile>,
but seems like element.Value does not work.
Appreciate any advices :)