SL4: Root element missing

I know this was asked elsewhere, but none of the questions and answers helped.
I open the xml file in my SL 4 application:

StreamResouceInfo sri =  Application.GetResourceStream(new System.Uri("z.xml", UriKind.Relative));
if (null != sri)
{
    XDocument xDoc = XDocument.Load(sri.Stream);
}

The Root Element exception is excluded.

xml:
 Hmm, it seems that it cannot post xml ... It is well-formed and valid, with a single root root and all tags are closed. Thanks for any tips ...

Try using angle brackets:

xml version="1.0" encoding="utf-8"
Root
    Collection name="Fonts"
        Value Lucida /Value
        Value Arial /Value
   /Collection
/Root
+3
source share
1 answer

I just had this problem. In the end, I just put the resulting stream in XmlReader, and then in XDocument.Load.

Your code will be

StreamResouceInfo sri =  Application.GetResourceStream(new System.Uri("z.xml", UriKind.Relative));
if (null != sri)
{
    XmlReader rdr = new XmlReader.Create(sri.Stream);
    XDocument xDoc = XDocument.Load(rdr);
}

In my case, I used a call to WebClient.DownloadStringAsync, so it was a little different

void getCacheData_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    if (e.Error == null)
    {
        StringReader stream = new StringReader(e.Result);
        XmlReader reader = XmlReader.Create(stream);
        XDocument doc = new XDocument.Load(reader);
    }
}
+1
source

Source: https://habr.com/ru/post/1747288/


All Articles