user
user

Reputation: 55

XDocument reference issue c#

I have these 2 methods wrote in another class, but how can I reach the output off this from other classes? I wan't just the value of lsTags.

That's my code:

private void LoadXMLFile()
    {
        WebClient xmlClient = new WebClient();
        xmlClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(XMLFileLoaded);
        xmlClient.DownloadStringAsync(new Uri("codeFragments.xml", UriKind.RelativeOrAbsolute));
    }
    private void XMLFileLoaded(object sender, DownloadStringCompletedEventArgs e)
    {            
        if (e.Error == null)
        {
            string xmlData = e.Result;
            XDocument xDoc = XDocument.Parse(xmlData);

            var tagsXml = from c in xDoc.Descendants("Tag") select c.Attribute("name");                

            foreach (string tagName in tagsXml)
            {
                Tag oTag = new Tag();
                oTag.name = tagName;
                var tags = from d in xDoc.Descendants("Tag")
                           where d.Attribute("name").Value == tagName
                           select d.Elements("oFragments");
                var tagXml = tags.ToArray()[0];

                foreach (var tag in tagXml)
                {
                    CodeFragments oFragments = new CodeFragments();
                    oFragments.tagURL = tag.Attribute("tagURL").Value;
                    //Tags.tags.Add(oFragments);
                    oTag.lsTags.Add(oFragments);
                }
                this.lsTags.Add(oTag);
            }
        }
    }

Upvotes: 1

Views: 270

Answers (1)

John Saunders
John Saunders

Reputation: 161791

Silverlight does not support XmlDocument. Use LINQ to XML instead.

Upvotes: 1

Related Questions