Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 572
  • Last Modified:

c# process xml file

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
jackjohnson44
Asked:
jackjohnson44
2 Solutions
 
Fernando SotoCommented:
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
 
Carl TawnSystems and Integration DeveloperCommented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now