public List<Cliente> LeerClientes() { List<Cliente> Client = new List<Cliente>(); doc = new XmlDocument(); doc.Load(ruta); XmlNodeList nodeList = doc.GetElementsByTagName("cliente"); foreach (XmlNode p in nodeList) { Cliente item = new Cliente(); item.Codigo = p["codigo"].InnerText; item.Nombre = p["nombre"].InnerText; item.Direccion = p["direccion"].InnerText; item.Telefono = Convert.ToInt32(p["telefono"].InnerText); Client.Add(item); } return Client; }
public Cliente BuscarCliente(String codigo) { Cliente cli = new Cliente(); doc = new XmlDocument(); doc.Load(ruta); XmlNodeList nodeList = doc.GetElementsByTagName("cliente"); foreach (XmlNode c in nodeList) { if (c["codigo"].InnerText.ToLower().Equals(codigo)) { cli= new Cliente(); cli.Codigo = c["codigo"].InnerText; cli.Nombre = c["nombre"].InnerText; cli.Direccion = c["direccion"].InnerText; cli.Telefono = Convert.ToInt32(c["telefono"].InnerText); } } return cli; }
private void button1_Click(object sender, EventArgs e) { ruta = Application.StartupPath + "\\data\\Clientes.xml"; FicheroXml fich = new FicheroXml(ruta); cliente=fich.BuscarCliente(this.txbCodigo.Text.Trim().ToLower()); cargaclientes(); }