using System; using System.IO; using System.Xml; public class XmlFromString { public static void Main(string[] args) { string xml = "<?xml version='1.0'?><person firstname='john' lastname='smith' />"; XmlDocument doc = new XmlDocument(); doc.InnerXml = xml; XmlElement root = doc.DocumentElement; Console.WriteLine(" The firstname : {0} lastname: {1}", root.GetAttribute("firstname"), root.GetAttribute("lastname")); } }
protected void Button1_Click(object sender, EventArgs e) { XDocument feedXML = XDocument.Load(Server.MapPath("Feed.xml")); var items = from item in feedXML.Descendants("item") select new { Description = item.Element("description").Value }; foreach(var item in items) { this.Label1.Text = item.Description; } }
<?xml version="1.0"?> <rss version="2.0"> <channel> <title>Latest P</title> <link>/P</link> <description>A brief overview of the weather for the week ahead.</description> <language>en-us</language> <item> <title>Tue 1/12 : 2 Stars</title> <link>/P</link> <description> Rating :: 2 Stars. SSSS :: 11 ft @ 7 secs. Wind :: 26mph SSE </description> </item> </channel> </rss>
j0e wrote: » yeah no worries, was trying the split() with a full stop to cut them, works fine untill on of the numbers goes to a decimal so, trying to find a way around that.