日期:2014-05-18  浏览次数:20359 次

XML读取子节点
XML内容如下.就是几张图片路径.
<table>
  <GGName>gct0925.gif</GGName>
  <GGName>bsqsp1010.gif</GGName>
  <GGName>wqd1220.gif</GGName>
  <GGName>qsb0614.gif</GGName>
  <GGName>putian070227.gif</GGName>
</table>
我又把图片放入一个文件夹.在页面上放入五个image图片框.然后从XML读取路径在给image图片框.

我现在想把XML里面读出的数据放入一个数组.然后Image1.ImageUrl= 这个图片的路径.在加载时显示.如何做.
也就是在XML获取子节点然后在给image 图片框.如何实现
最好写上代码.谢谢

------解决方案--------------------
C# code
void Page_Load(object sender, EventArgs e)
    {
        //Location of XML file
        string xmlFilePath = Request.PhysicalApplicationPath + @"Employees.xml";    
        //Create the XmlReaderSettings object and set appropriate properties
        XmlReaderSettings settings = new XmlReaderSettings();
        settings.IgnoreComments = true;
        settings.IgnoreWhitespace = true;
        try
        {
            //Get reference to the XmlReader object
            using (XmlReader reader = XmlReader.Create(xmlFilePath, settings))
            {
                string result;
                while (reader.Read())
                {
                    //Process only the elements
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        for (int count = 1; count <= reader.Depth; count++)
                        {
                             result += "=> " + reader.Name + "<br/>";
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            lblResult.Text = "An Exception occurred: " + ex.Message;
        }
    }