XmL file is not loading in Listbox
I have vb code along with xml.and i need to populate simple xml file in list box in silverlight appliction ,but its not rendering any thing
Code:
<UserControl xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<Grid x:Name="LayoutRoot" Background="White">
<ListBox x:Name="customersList" Width="400" Height="200" />
</Grid>
</UserControl>
Code:
Private Sub PopulateCustomersList()
Dim settings As New XmlReaderSettings()
settings.XmlResolver = New XmlXapResolver()
Dim reader As XmlReader = XmlReader.Create("Customers.xml")
reader.MoveToContent()
While reader.Read()
If reader.NodeType = XmlNodeType.Element AndAlso reader.Name = "customer" Then
customersList.Items.Add(New ListBoxItem())
End If
If reader.NodeType = XmlNodeType.EndElement AndAlso reader.Name = "customers" Then
Exit While
End If
End While
reader.Close()
End Sub
Code:
Private Sub Btn_hello_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
MessageBox.Show("Hello World")
PopulateCustomersList()
End Sub
Re: XmL file is not loading in Listbox
here is the .xml file
Code:
<?xml version="1.0"?>
<customers>
<customer id="10001" first="John" last="Smith" company="Donuts plc">[email protected]</customer>
<customer id="10002" first="Rete" last="Bandy" company="This Is Bloggers Co.">[email protected]</customer>
<customer id="10003" first="James" last="Bird" company="Timestone">[email protected]</customer>
<customer id="10004" first="Sarah" last="McCauly" company="Automated Snowmen Ltd">[email protected]</customer>
<customer id="10005" first="Pete" last="Rowan" company="Cooltec Consultants">[email protected]</customer>
</customers>
Re: XmL file is not loading in Listbox
What's a ListBoxItem? Doesn't surprise me nothing is rendering... I don't see where you extract any data from the XML and add it to the ListBox.
-tg
Re: XmL file is not loading in Listbox
took reference from here
http://www.vectorlight.net/tutorials...lverlight.aspx
and out put is showing over there
Re: XmL file is not loading in Listbox
of course THAT example works... the data was extracted from the XML:
Code:
customersList.Items.Add(new ListBoxItem() { Content = reader.GetAttribute("last") + ", " + reader.GetAttribute("first") + " (" + reader.ReadInnerXml() + ")" });
When you copied it over and converted it to VB, you didn't inlcude the reader.GetAttribute parts...
-tg
Re: XmL file is not loading in Listbox
hmm, fair enough can u please correct the missing statment in this i.e
Code:
While reader.Read()
If reader.NodeType = XmlNodeType.Element AndAlso reader.Name = "customer" Then
customersList.Items.Add(New ListBoxItem() Content = reader.GetAttribute("last") & ", " & reader.GetAttribute("first") & " (" & reader.ReadInnerXml() & ")" & )
End If
If reader.NodeType = XmlNodeType.EndElement AndAlso reader.Name = "customers" Then
Exit While
End If
End While