Solved

c# process xml file

Posted on 2014-04-01
2
566 Views
Last Modified: 2016-02-18
I have the following xml file and need to loop through and process the js and css nodes in two steps. First I want to loop through the js, then the css.


<?xml version="1.0" encoding="utf-8" ?>
<files>
  <js>/_layouts/dir1/exportandsendwidget.js</js>
  <js>/_layouts/dir2/fm_grid_utils.js</js>
  <css>/_layouts/1033/test.css</css>
  <css>/_layouts/1033/test2.css</css>
</files>

Open in new window

0
Comment
Question by:jackjohnson44
[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
2 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 250 total points
ID: 39969609
Hi jackjohnson44;

The following Linq queries will return the need values from the XML data.

// Open the XML document from the path given
XDocument xdoc = XDocument.Load("Path & filename");

// Get the js values as a List of strings
List<string> jsResults = xdoc.Descendants("js")
                             .Select( js => js.Value ).ToList();

// Get the css values as a List of strings
List<string> cssResults = xdoc.Descendants("css")
                              .Select( css => css.Value ).ToList();

Open in new window

You then can use a for each loop to process the individual values of each list.
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 250 total points
ID: 39969607
Try something like:
            XmlDocument doc = new XmlDocument();
            doc.LoadXml("Your xml");

            foreach(XmlNode node in doc.SelectNodes("//js"))
            {
                // do something
            }

            foreach(XmlNode node in doc.SelectNodes("//css"))
            {
                // do something
            }

Open in new window

0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

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…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

617 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