using System;
using System.Core;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
using System.Net;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
namespace graf
{
public partial class Page : UserControl
{
public Page()
{
// Required to initialize variables
InitializeComponent();
//AnimationTimer.Begin();
AnimationTimer.Completed += new EventHandler(OnTick);
Stream s = this.GetType().Assembly.GetManifestResourceStream("out.xml");
XmlReader reader = XmlReader.Create(s);
XElement elementRoot = XElement.Load(reader);
var elements = from element in elementRoot.Descendants("osoba")
select new
{
Attribute1 = (string)element.Attribute("meno"),
Attribute2 = (string)element.Attribute("xxx")
};
foreach (var element in elements)
{
string a = element.Attribute1;
string b = element.Attribute2;
}
}
}
}
sith123
Member
20 Points
12 Posts
Re: Re: Re: Re: how to parse xml in silverlight2?
Mar 20, 2008 12:45 PM | LINK
using System;
using System.Core;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
using System.Net;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
namespace graf
{
public partial class Page : UserControl
{
public Page()
{
// Required to initialize variables
InitializeComponent();
//AnimationTimer.Begin();
AnimationTimer.Completed += new EventHandler(OnTick);
}
..... some functions
private void nacitajXML(object sender, System.Windows.RoutedEventArgs e)
{
Stream s = this.GetType().Assembly.GetManifestResourceStream("out.xml");
XmlReader reader = XmlReader.Create(s);
XElement elementRoot = XElement.Load(reader);
var elements = from element in elementRoot.Descendants("osoba")
select new
{
Attribute1 = (string)element.Attribute("meno"),
Attribute2 = (string)element.Attribute("xxx")
};
foreach (var element in elements)
{
string a = element.Attribute1;
string b = element.Attribute2;
}
}
}
}
jjy2
Member
354 Points
155 Posts
Re: Re: Re: Re: how to parse xml in silverlight2?
Mar 20, 2008 10:00 PM | LINK
That compiles ok for me.
Is it possible that you added two different versions of Linq assembly reference?
sith123
Member
20 Points
12 Posts
Re: Re: Re: Re: Re: how to parse xml in silverlight2?
Mar 20, 2008 10:16 PM | LINK
it is possible, how can i find the good one?
jjy2
Member
354 Points
155 Posts
Re: Re: Re: Re: Re: how to parse xml in silverlight2?
Mar 20, 2008 10:34 PM | LINK
I think somehow you have loaded two implementation of Enumerable class?
Before you install SL2 did you uninstall SL1.1 SDK, Tools, Runtime completely?
If that is only a test project and if you can post it to somewhere, I will attemp to build the project for you to see if it compiled with my machine.
sith123
Member
20 Points
12 Posts
Re: Re: Re: Re: Re: Re: how to parse xml in silverlight2?
Mar 21, 2008 10:49 AM | LINK
I made a new priject and it was build without mistakes. Im happy.
But :P I have problem with first line of your code, it is not working. :(
jjy2
Member
354 Points
155 Posts
Re: Re: Re: Re: Re: Re: how to parse xml in silverlight2?
Mar 21, 2008 11:06 AM | LINK
In your code,
Stream s = this.GetType().Assembly.GetManifestResourceStream("out.xml");
Change out.xml to "graf.out.xml"
That is, "[Your Namespace].[Embeded resource file name]" will be your embeded resource name.
jjy2
Member
354 Points
155 Posts
Re: Re: Re: Re: Re: Re: how to parse xml in silverlight2?
Mar 21, 2008 11:15 AM | LINK
I can see where it went wrong. When I typed the example, I just maded it up resource name.
Shouldn't have done that..
Sith, may the force be with you :-)
sith123
Member
20 Points
12 Posts
Re: Re: Re: Re: Re: Re: Re: how to parse xml in silverlight2?
Mar 21, 2008 11:32 AM | LINK
hmm, I dont understand what is wrong, maybe becouse Im realy tired :D
jjy2
Member
354 Points
155 Posts
Re: Re: Re: Re: Re: Re: Re: how to parse xml in silverlight2?
Mar 21, 2008 11:42 AM | LINK
Still having problem after changed resource name?
Did you change "build action" in Properties window to "Embeded Resource" for out.xml file?
[EDIT]
See also Documentation -> Core Presentation Framework /UI -> Application Development -> Resource Files
There are other ways to include your resource file.
I personally prefer to xap them ([Build Action] to [Content])
sith123
Member
20 Points
12 Posts
Re: Re: Re: Re: Re: Re: Re: Re: how to parse xml in silverlight2?
Mar 21, 2008 01:30 PM | LINK
still having a problem. How can I add resource? I can only add item, but There are no properities to change.