?
Solved

How to pharse XML (XmlElement element)

Posted on 2014-03-10
1
Medium Priority
?
315 Views
Last Modified: 2014-03-11
Hi

I have a variable which is

(XmlElement element)

I will to test element by assigning it

element = "<?xml version="1.0" encoding="UTF-8"?><note><to> Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>"


the problem I get is the XML has to be pharsed, does anyone know how I can get this to work?

thanks
0
Comment
Question by:mousemat24
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 39918447
Hi mousemat24;

See if something like this is what you are looking for.

using System.Xml.Linq;

string element = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><note><to> Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>";
           
XDocument xdoc = XDocument.Parse(element);

var parsed = (from x in xdoc.Descendants("note")
              select new
              {
                  To = x.Element("to").Value,
                  From = x.Element("from").Value,
                  Heading = x.Element("heading").Value,
                  Body = x.Element("body").Value
              }).ToList();
  
             
foreach (var p in parsed)
{
    Console.WriteLine("TO : {0}\nFrom : {1}\nHeading : {2}\nBody : {3}", p.To, p.From, p.Heading, p.Body);
}             

Open in new window

0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question