Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Read XML File
8 replies. Latest Post by natarajkt on January 17, 2008.
(0)
Tuizi
Member
177 points
90 Posts
12-24-2007 12:51 PM |
Hello,
How I can read a XML File in Silverlight?
I try:
bddXML.Read();
But I get an Exception :(
The XML File is in my project.
Thank a lot
Fdream
86 points
23 Posts
12-25-2007 1:14 AM |
Read it like this: Uri requestUri = new Uri("path_to_my_xmlfile", UriKind.Relative); HttpWebRequest request = new BrowserHttpWebRequest(requestUri); request.Connection = "Close"; HttpWebResponse response = request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { responseStatus = HttpStatusCode.OK; Stream content = response.GetResponseStream(); XmlReader reader = XmlReader.Create(new StreamReader(content, Encoding.UTF8)); while (reader.Read()) { // your code here }
Related article: How to: Send and Receive Plain XML Requests and Responses over HTTP
12-25-2007 8:05 AM |
I get an exception on the line:
HttpWebResponse
Operation is not valid due to the current state of the object.
Thank
12-25-2007 7:55 PM |
For local file, you can try this:
Stream s = this.GetType().Assembly.GetManifestResourceStream("LoadXml.your_xml_file.xml");using (XmlReader reader = XmlReader.Create(s)) { while (reader.Read()) { //your codes here }}
For more information about GetManifestResourceStream, you can check it in MSDN.
12-26-2007 2:05 AM |
Thank for your answer.
When I do that, s is null, so, the XML File must have a specific characteristic ?
The path must be: LoadXml.my_file.xml or LoadXml.C:\\myproject\\myfile.xml ?
12-26-2007 7:21 AM |
Lol I'm a newbee... :p
natarajkt
6 points
4 Posts
01-16-2008 10:25 AM |
Hi.. I tried to read an xml file stored in a location say "c:\". But the GetManifestResourceStream() always returns null.
Cant I read a file external to the project?
my code:
{
}
where SilverlightProject2 is my namespace name.
mario_mh
498 points
116 Posts
01-16-2008 11:44 AM |
hi,
you can't read files from the file system ... this is a security issue.
01-17-2008 11:50 PM |
Hi Mario,
Iam trying to deploy silverlight application in a cdrom. The silverlight application will be embedded in a HTML page and it will run from a webserver launced from cdrom. Is there any way i can access the images and xml files stored in the cdrom from silverlight application.
thanks,
nataraj