Daniel Golan

Daniel Golan

  • NA
  • 45
  • 47.6k

Reading node by name

Jan 8 2011 2:58 AM
Hello =)


            if (lab_url.Text == "")
            {
                lab_url.Text = "C:/Users/Daxal/documents/visual studio 2010/Projects/Yr/Yr/XML/fjellstrand.xml";
            }

            //open xml
            XDocument xmlDoc = XDocument.Load("C:/Users/Daxal/Dropbox/C#/Yr/Yr/XML/url.xml");
            //read xml
            var xmlAtt = from att in xmlDoc.Elements("yrurl").Elements("Name").Attributes("Url")
                         select att;
            foreach (var loc in xmlAtt)
            {
                lab_url.Text = loc.Value;
            } 

which is reading the xml :

<?xml version="1.0"?>
<yrurl>
  
<Name Url ="http://www.yr.no/sted/Norge/Oslo/Oslo/Oslo/varsel.xml">Oslo</Name>

<Name Url ="http://www.yr.no/sted/Norge/Akershus/Ski/Ski/varsel.xml">Ski</Name>


</yrurl>

How can i use the c# code to only read the url from oslo (in the xml) ?

Any hints or tips are greatly appriciated ! :)

Answers (2)