public void GetPostagemXml(ArrayList array) { XmlReader xml = XmlReader.Create(@".\Contas\postagens.xml"); while (xml.ReadToFollowing("POST")) { Postagem post = new Postagem(); xml.ReadToFollowing("data"); post.Data = xml.ReadElementContentAsString(); xml.ReadToFollowing("hora"); post.Hora = xml.ReadElementContentAsString(); xml.ReadToFollowing("usuario"); post.Usuario = xml.ReadElementContentAsString(); xml.ReadToFollowing("nome"); post.Nome = xml.ReadElementContentAsString(); xml.ReadToFollowing("endereco"); post.CompEndereco = xml.ReadElementContentAsString(); xml.ReadToFollowing("cargo"); post.Cargo = xml.ReadElementContentAsString(); xml.ReadToFollowing("numero"); post.NumVagas = xml.ReadElementContentAsString(); xml.ReadToFollowing("desejavel"); if (xml.ReadElementContentAsString() == "True") { post.Desejavel = true; } else { post.Desejavel = false; } if (post.Desejavel == true) { xml.ReadToFollowing("DESEJAVEL"); GetRequisitos(post.DesCur, xml, "curso"); GetRequisitos(post.DesFer, xml, "ferramenta"); GetRequisitos(post.DesIdi, xml, "idioma"); GetRequisitos(post.DesExp, xml, "experiencia"); } xml.ReadToFollowing("necessario"); if (xml.ReadElementContentAsString() == "True") { post.Necessario = true; } else { post.Necessario = false; } if (post.Necessario == true) { xml.ReadToFollowing("NECESSARIO"); GetRequisitos(post.DesCur, xml, "curso"); GetRequisitos(post.DesFer, xml, "ferramenta"); GetRequisitos(post.DesIdi, xml, "idioma"); GetRequisitos(post.DesExp, xml, "experiencia"); } array.Add(post); } }
public void SetPostagemXml(ArrayList posts) { XmlTextWriter dxml = new XmlTextWriter(@".\Contas\postagens.xml", null); try { dxml.WriteStartDocument(); dxml.Formatting = Formatting.Indented; dxml.WriteStartElement("POSTAGENS"); int i = 0; foreach (var ele in posts) { Postagem p = (Postagem)ele; dxml.WriteStartElement("POST"); dxml.WriteAttributeString("id", "" + i); dxml.WriteElementString("tipo", "" + p.Tipo); dxml.WriteElementString("data", p.Data); dxml.WriteElementString("hora", p.Hora); dxml.WriteElementString("usuario", p.Usuario); dxml.WriteElementString("nome", p.Nome); dxml.WriteElementString("endereco", p.CompEndereco); dxml.WriteElementString("cargo", p.Cargo); dxml.WriteElementString("numero", p.NumVagas); dxml.WriteElementString("desejavel", "" + p.Desejavel); if (p.Desejavel == true) { dxml.WriteStartElement("DESEJAVEL"); WriteArray(p.DesCur, "curso", dxml); WriteArray(p.DesFer, "ferramenta", dxml); WriteArray(p.DesIdi, "idioma", dxml); WriteArray(p.DesExp, "experiencia", dxml); dxml.WriteEndElement(); } dxml.WriteElementString("necessario", "" + p.Necessario); if (p.Necessario == true) { dxml.WriteStartElement("NECESSARIO"); WriteArray(p.NesCur, "curso", dxml); WriteArray(p.NesFer, "ferramenta", dxml); WriteArray(p.NesIdi, "idioma", dxml); WriteArray(p.NesExp, "experiencia", dxml); dxml.WriteEndElement(); } dxml.WriteEndElement(); if (p.Inscritos.Count > 0) { dxml.WriteStartElement("INSCRITOS"); foreach (var ment in p.Inscritos) { dxml.WriteStartElement("user"); dxml.WriteAttributeString("id", ment.ToString()); dxml.WriteEndElement(); } } } dxml.WriteFullEndElement(); dxml.Close(); } catch (Exception ex) { dxml.Close(); MessageBox.Show(String.Format("Erro ao Guardar XML: {0}\nOrigem: {1}", ex.Message, ex.Source), "Erro!", MessageBoxButton.OK, MessageBoxImage.Error); } }