xml file :
<customers>
<customer age="19" gender="female">
<name>Kevin Anders</name>
<phone>555.555.5555</phone>
</customer>
<customer age="22" gender="male">
<name>Staci Richard</name>
<phone>555.122.1552</phone>
</customer>
</customers>
using System;
using System.Xml;
namespace XML
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load("test.xml");
XmlNodeList customers = doc.SelectNodes("//customer");
foreach (XmlNode customer in customers)
{
Console.WriteLine("Age = {0}, Gender = {1}", customer.Attributes["age"].Value, customer.Attributes["gender"].Value);
}
Console.ReadLine();
}
}
}
XML :
XML :
<?xml version="1.0" encoding="ISO-8859-1"?>
<Setting>
<General_Properties>
<imagesXML value="images.xml"/>
<direction value="horizontal" />
<minThumbWidth value="50" />
<minThumbHeight value="50" />
<maxThumbWidth value="120" />
<maxThumbHeight value="120" />
<spacing value="5" />
<expandingDirection value="center" />
<imagesEasingSpeed value="70" />
<imagesInfluence value="200" />
<backgroundColor value="0xeeeeee" />
<dockWidth value="570" />
<dockHeight value="200" />
<startingPixel value="0" />
<gotoStartingPixelOnRollOut value="false" />
</General_Properties>
</Setting>
using System;
using System.Xml;
namespace XML
{
///
/// Summary description for Class1.
///
class Class1
{
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load("settings.xml");
XmlNodeList imagesXML = doc.SelectNodes("//imagesXML");
foreach (XmlNode name in imagesXML)
{
Console.WriteLine("Value {0}", name.Attributes["value"].Value);
}
///
XmlNodeList direction = doc.SelectNodes("//direction");
foreach (XmlNode name in direction)
{
Console.WriteLine("Value {0}", name.Attributes["value"].Value);
}
Console.ReadLine();
}
}
}
No comments:
Post a Comment