Solved

c# process xml file

Posted on 2014-04-01
2
564 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

751 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