I have a XML
:
<paises>
<pais>
<nome-pais>África do Sul</nome-pais>
<consulados>
<consulado>
<nome-consulado>Consulado da República da África do Sul</nome-consulado>
<endereco>Av. Paulista 1754, 12º andar</endereco>
<cep>01310-100</cep>
<telefones>
<telefone>(11)3265-0449</telefone>
<telefone>(11)3265-0540</telefone>
</telefones>
</consulado>
</consulados>
</pais>
<pais>
<nome-pais>Albânia</nome-pais>
<consulados>
<consulado>
<nome-consulado>Consulado da República da Albânia</nome-consulado>
<cep>01310-100</cep>
<telefone>(11) 3283-3305</telefone>
</consulado>
</consulados>
</pais>
When I read the phones, it always doubles:
CodeC#
:
XDocumentxmlDoc=XDocument.Load(XmlReader.Create(@"XML\consulados_pt.xml"));
var result2 = (from p in xmlDoc.Descendants("pais")
let Nomepais = p.Element("nome-pais").Value
from f in xmlDoc.Descendants("telefones")
.SelectMany(x=> x.Elements("telefone")
.Select(t=>t.Value))
let telefone = f
where Nomepais == SSP.Consulado.pais
select new ListaConsulado.Consulado()
{
NomePais = Nomepais,
Telefone = "Tel: " + telefone
}
).ToList();
obs: I put this code let telefone = f
just for testing!
- I wanted to get the 2 phones, without duplicating the list
- And there's another detail, when I open another list item, it brings those even phones:
<telefone>(11)3265-0449</telefone><telefone>(11)3265-0540</telefone>
XAMLemcasodedúvidas
<phone:LongListSelectorName="lstCons"
HorizontalAlignment="Center"
VerticalAlignment="Top"
LayoutMode="List"
IsGroupingEnabled="False"
Width="456" SelectionChanged="lstCons_SelectionChanged" >
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<Border BorderBrush="#111" Background="Transparent" Margin="0, 10, 0, 0" BorderThickness="0,0,0,2">
<StackPanel VerticalAlignment="Center" Orientation="Vertical" >
<TextBlock Text="{Binding NomeConsulado}" HorizontalAlignment="Left" VerticalAlignment="Center" Style="{StaticResource PhoneTextTitle3Style}"/>
<TextBlock Text="{Binding Endereco}" HorizontalAlignment="Left" VerticalAlignment="Center" Style="{StaticResource PhoneTextSmallStyle}"/>
<TextBlock Text="{Binding Cep}" HorizontalAlignment="Left" VerticalAlignment="Center" Style="{StaticResource PhoneTextSmallStyle}"/>
<TextBlock Text="{Binding Telefone}" HorizontalAlignment="Left" VerticalAlignment="Center" Style="{StaticResource PhoneTextSmallStyle}"/>
</StackPanel>
</Border>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>