Skip to content

Instantly share code, notes, and snippets.

@vanhouc
Last active August 29, 2015 13:55
Show Gist options
  • Save vanhouc/8725391 to your computer and use it in GitHub Desktop.
Save vanhouc/8725391 to your computer and use it in GitHub Desktop.
Some clever XML reading
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Linq;
namespace SystemCheckerPlus
{
class XMLService
{
private XDocument _doc;
public XMLService(IXDocProvider loader)
{
if (loader.Doc != null)
_doc = loader.Doc;
}
public string GetElementValue(string[] elementChain)
{
IEnumerable<XElement> scope = _doc.Descendants();
for (int i = 0; i < elementChain.Length - 1; i++ )
{
scope = scope.Single(x => x.Name == elementChain[i]).Descendants();
}
return scope.Single(x => x.Name == elementChain[elementChain.Length - 1]).Value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment