Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

c# process xml file

Posted on 2014-04-01
2
Medium Priority
?
568 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 64

Accepted Solution

by:
Fernando Soto earned 1000 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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

715 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