using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using Winson.Framework.Utility;

public partial class XMLTest : System.Web.UI.Page
{
    string value;

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void GetValue_Click(object sender, EventArgs e)
    {
        XmlHelper xmlOP = new XmlHelper();
        string file=Server.MapPath("XMLDataBase/Test.xml");
        xmlOP.LoadXML(file, XmlHelper.LoadType.FromLocalFile);
        
        XmlNode root = xmlOP.RootNode;
        //value = xmlOP.GetChildElementValue(root.SelectNodes("Records")[0], "Id");

        //value = xmlOP.GetChildElementValue(root, "Records");
        XmlNodeList nl = xmlOP.GetChildNodesFromRoot("Records");

        xmlOP.CreateNodeElement(root, "Records", "<Id>05</Id><Name>R_Roger</Name>");
        value = xmlOP.SaveToFile(file).ToString();
        
        //select 
        //foreach (XmlNode node in nl)
        //{
        //    if (xmlOP.GetChildElementValue(node, "Context").IndexOf("asf") > -1)
        //    {
        //        value += xmlOP.GetChildElementValue(node, "Name")+",";
        //    }
        //}

        //update
        foreach (XmlNode node in nl)
        {
            if (xmlOP.GetChildElementValue(node, "Id").Equals("01"))
            {
              //  xmlOP.ModifyNodeElementValue(xmlOP.GetChildElement(node.ChildNodes, "Name"), "ok");
              //  value = xmlOP.SaveToFile(file).ToString();
            }
        }




        Response.Write("value: "+value);
    }
}
