I am trying to create a C# Windows Blank App that has a simple webview that cycles through multiple URLs obtained from an XML file.
This is what I have so far:
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;
//creates url array
List<Uri> listUri = new List<Uri>();
listUri.Add(new Uri("http://www.bing.com/"));
listUri.Add(new Uri("https://www.youtube.com/"));
listUri.Add(new Uri("http://hsrg.lsu.edu/"));
foreach (Uri value in listUri)
{
webView.Navigate(value);
}
}
I don't know how to browse and use an XML file so I have an list setup right now. Any help would be appreciated!
You can use LINQ to XML to parse the URLs in XML file like this:
XElement xelement = XElement.Load("URLs.xml");
IEnumerable<XElement> urls = xelement.Elements();
foreach (var url in urls)
{
var value = url.Element("Address").Value;
webView.Navigate(new Uri(value));
}
And the URLs.xml like this:
<?xml version="1.0" encoding="utf-8" ?>
<Urls>
<Url>
<Address>http://www.bing.com/</Address>
</Url>
<Url>
<Address>https://www.youtube.com/</Address>
</Url>
<Url>
<Address>http://hsrg.lsu.edu/</Address>
</Url>
</Urls>