using System.Collections.Generic;
public string CodigoRetorno { get; set; }
public string MensagemRetorno { get; set; }
public string QtdRegistros { get; set; }
public string CodigoHash { get; set; }
public string Metodo { get; set; }
public string NumeroSolicitante { get; set; }
public string NumeroRecebedor { get; set; }
public string TipoRegistro { get; set; }
public string DataSolicitacao { get; set; }
public string NomeRegistrado1 { get; set; }
public string NomeRegistrado2 { get; set; }
public string NovoNomeRegistrado1 { get; set; }
public string NovoNomeRegistrado2 { get; set; }
public string DataOcorrido { get; set; }
public string DataRegistro { get; set; }
public string Matricula { get; set; }
public string ObsSolicitacao { get; set; }
public string Emolumentos { get; set; }
private static string xml =
@"<?xml version=""1.0"" encoding=""UTF-8"" ?>
<codigo_retorno>99999</codigo_retorno>
<mensagem_retorno>OK</mensagem_retorno>
<qtd_registros>0</qtd_registros>
<codigo_hash>adf45as6d546a5sd4654asd</codigo_hash>
<numero_solicitante>1234</numero_solicitante>
<numero_recebedor>43211</numero_recebedor>
<tipo_registro>555</tipo_registro>
<data_solicitacao>2015-01-01</data_solicitacao>
<nome_registrado_1>JOHN DOE</nome_registrado_1>
<nome_registrado_2>JANE DOE</nome_registrado_2>
<novo_nome_registrado_1>TESTE TESTE</novo_nome_registrado_1>
<novo_nome_registrado_2>FOO</novo_nome_registrado_2>
<data_ocorrido>2015-02-01</data_ocorrido>
<data_registro>2015-02-03</data_registro>
<matricula>asd5465465</matricula>
<obs_solicitacao>Lorem Ipsum Dolor Sit Amet</obs_solicitacao>
<emolumentos>0</emolumentos>
<codigo_hash>asdlkasdljasdljknasdljknds</codigo_hash>
<numero_solicitante>454564</numero_solicitante>
<numero_recebedor>487897</numero_recebedor>
<tipo_registro>asd456</tipo_registro>
<data_solicitacao>2015-01-01</data_solicitacao>
<nome_registrado_1>JOHN DOE</nome_registrado_1>
<nome_registrado_2>JANE DOE</nome_registrado_2>
<novo_nome_registrado_1>TESTE TESTE</novo_nome_registrado_1>
<novo_nome_registrado_2>FOO</novo_nome_registrado_2>
<data_ocorrido>2015-02-01</data_ocorrido>
<data_registro>2015-02-03</data_registro>
<matricula>asd5465465</matricula>
<obs_solicitacao>Lorem Ipsum Dolor Sit Amet</obs_solicitacao>
<emolumentos>0</emolumentos>
<codigo_hash>sdoiasdio=jasdçkljasd</codigo_hash>
<numero_solicitante>645646</numero_solicitante>
<numero_recebedor>4654656</numero_recebedor>
<tipo_registro>888</tipo_registro>
<data_solicitacao>2015-01-01</data_solicitacao>
<nome_registrado_1>JOHN DOE</nome_registrado_1>
<nome_registrado_2>JANE DOE</nome_registrado_2>
<novo_nome_registrado_1>TESTE TESTE</novo_nome_registrado_1>
<novo_nome_registrado_2>FOO</novo_nome_registrado_2>
<data_ocorrido>2015-02-01</data_ocorrido>
<data_registro>2015-02-03</data_registro>
<matricula>asd5465465</matricula>
<obs_solicitacao>Lorem Ipsum Dolor Sit Amet</obs_solicitacao>
<emolumentos>0</emolumentos>
public static void Main()
XDocument doc = XDocument.Parse(xml);
List<Certidao> certidoes = new List<Certidao>();
foreach (var elmCertidao in doc.Root.Elements("certidao"))
Certidao certidao = new Certidao()
CodigoRetorno = GetValueOrDefault(doc.Root.Element("codigo_retorno")),
MensagemRetorno = GetValueOrDefault(doc.Root.Element("mensagem_retorno")),
QtdRegistros = GetValueOrDefault(doc.Root.Element("qtd_registros")),
CodigoHash = GetValueOrDefault(elmCertidao.Element("codigo_hash")),
Metodo = GetValueOrDefault(elmCertidao.Element("metodo")),
NumeroSolicitante = GetValueOrDefault(elmCertidao.Element("numero_solicitante")),
NumeroRecebedor = GetValueOrDefault(elmCertidao.Element("numero_recebedor")),
TipoRegistro = GetValueOrDefault(elmCertidao.Element("tipo_registro")),
DataSolicitacao = GetValueOrDefault(elmCertidao.Element("data_solicitacao")),
NomeRegistrado1 = GetValueOrDefault(elmCertidao.Element("nome_registrado_1")),
NomeRegistrado2 = GetValueOrDefault(elmCertidao.Element("nome_registrado_2")),
NovoNomeRegistrado1 = GetValueOrDefault(elmCertidao.Element("novo_nome_registrado_1")),
NovoNomeRegistrado2 = GetValueOrDefault(elmCertidao.Element("novo_nome_registrado_2")),
DataOcorrido = GetValueOrDefault(elmCertidao.Element("data_ocorrido")),
DataRegistro = GetValueOrDefault(elmCertidao.Element("data_registro")),
Matricula = GetValueOrDefault(elmCertidao.Element("matricula")),
ObsSolicitacao = GetValueOrDefault(elmCertidao.Element("obs_solicitacao")),
Emolumentos = GetValueOrDefault(elmCertidao.Element("emolumentos"))
foreach(var certidao in certidoes)
Console.WriteLine("**********");
Console.WriteLine(certidao.CodigoRetorno);
Console.WriteLine(certidao.MensagemRetorno);
Console.WriteLine(certidao.QtdRegistros);
Console.WriteLine(certidao.CodigoHash);
Console.WriteLine(certidao.Metodo);
Console.WriteLine(certidao.NumeroSolicitante);
Console.WriteLine(certidao.NumeroRecebedor);
Console.WriteLine(certidao.TipoRegistro);
Console.WriteLine(certidao.DataSolicitacao);
Console.WriteLine(certidao.NomeRegistrado1);
Console.WriteLine(certidao.NomeRegistrado2);
Console.WriteLine(certidao.NovoNomeRegistrado1);
Console.WriteLine(certidao.NovoNomeRegistrado2);
Console.WriteLine(certidao.DataOcorrido);
Console.WriteLine(certidao.DataRegistro);
Console.WriteLine(certidao.Matricula);
Console.WriteLine(certidao.ObsSolicitacao);
Console.WriteLine(certidao.Emolumentos);
public static string GetValueOrDefault(XElement xElement) {