Solved

How to pharse XML (XmlElement element)

Posted on 2014-03-10
1
311 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 500 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c#, datatable, aspx 4 44
Windows Universal App 22 51
SSIS Column mapping 5 37
VS C# how to design libary of functions 7 26
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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