Last active
June 10, 2021 23:07
-
-
Save robsonfaxas/cbe21aa4cb1c6682350913c309855922 to your computer and use it in GitHub Desktop.
[LinqToXml - criação] Exemplo de linq to XML para criação de um XML #linq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void CriarXmlLinq() | |
{ | |
XElement contatos = | |
new XElement("Contatos", | |
new XElement("Contato", | |
new XElement("Nome", "Thiago Mônaco"), | |
new XElement("Telefones", | |
new XElement("Telefone", "(11) 9999-9999", | |
new XAttribute("Tipo", "Celular")), | |
new XElement("Telefone", "(11) 5555-5555", | |
new XAttribute("Tipo", "Residencial")) | |
), | |
new XElement("Endereco", | |
new XElement("Logradouro", "R: Xpto, 1234"), | |
new XElement("Bairro", "Bairro XXX"), | |
new XElement("Cidade", "São Paulo"), | |
new XElement("Estado", "SP"), | |
new XElement("CEP", "01010-010") | |
) | |
), | |
new XElement("Contato", | |
new XElement("Nome", "Paulo Pedro"), | |
new XElement("Telefones", | |
new XElement("Telefone", "(11) 8888-8888", | |
new XAttribute("Tipo", "Celular")), | |
new XElement("Telefone", "(11) 4444-4444", | |
new XAttribute("Tipo", "Residencial")) | |
), | |
new XElement("Endereco", | |
new XElement("Logradouro", "R: ABC, 1234"), | |
new XElement("Bairro", "Bairro AAA"), | |
new XElement("Cidade", "São Paulo"), | |
new XElement("Estado", "SP"), | |
new XElement("CEP", "02020-020") | |
) | |
) | |
); | |
contatos.Save(@"C:\Curso\C#\Linq\Contatos2.xml"); | |
Console.WriteLine(@"Criando o arquivo XML com LINQ to XML em C:\Curso\C#\Linq\Contatos2.xml"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment