like this:
XmlTextReader tr = new XmlTextReader(filename);
while (tr.Read())
{
if (tr.NodeType == XmlNodeType.Element)
{
switch (tr.LocalName)
{
case ("FILENAME"):
_fileName= int.Parse(tr.ReadString());
break;
}
}
}
but your xml would need to look like this:
<ROOT>
<FILENAME>CDATA</FILENAME>
</ROOT>
that would do it.
> Hi,
> my xml is:
[quoted text clipped - 7 lines]
> GetElementByTagname("FILE)[0].Attribute retrieves attributelist
> how do i get the value of attribute????
Saurabh - 30 Sep 2006 07:49 GMT
Thanks Daniel, i learned a new way to access XML.
The problem is that the xml has to look like:
<ROOT>
<FILE NAME="filename"></FILE>
</ROOT>
beacuse the xml is generated by a recursive function which scans the
file system (DirectoryInfo ans FileInfo class) and generate a xml. The
exact xxml format is:
<ROOT>
<DIRECTORY>
<FILE NAME="filename">CDATA contains filestream</FILE>
<FILE NAME="filename">CDATA contains filestream</FILE>
</DIRECTORY>
<DIRECTORY>
<FILE NAME="filename">CDATA contains filestream</FILE>
<FILE NAME="filename">CDATA contains filestream</FILE>
</DIRECTORY>
</ROOT>
you never know if the filename can be same with different extension.
just to be precautious i have made the file tag with filename as
attribute.
GVN - 30 Sep 2006 12:56 GMT
Hi Saurabh,
I hope the following code should help you.
XmlDocument _Document = new XmlDocument();
XmlNodeList properties;
_Document.Load (XmlFileName);
XmlNodeList properties = _Document["Design"].ChildNodes;
foreach (XmlNode property in properties)
{
if(property.HasChildNodes)
{
XmlNodeList childNodes = property.ChildNodes;
foreach(XmlNode childNode in childNodes)
{
MessageBox.Show(childNode.Attributes["FILE"].Value); // You can
show file name.
}
}
}
Thanks,
Muralidhar GVN
> Thanks Daniel, i learned a new way to access XML.
> The problem is that the xml has to look like:
[quoted text clipped - 19 lines]
> just to be precautious i have made the file tag with filename as
> attribute.