Accepted answer

your first line doesn't do anything if you don't actually use the results.

foreach (var outputelement in rootelement.elements("output")
                                         .where(e => (string)e.attribute("id") == "1"))
    foreach (var pathelement in outputelement.elements("path"))
        // ...

if your id attribute is guaranteed to be unique (which it should), you can get rid of the first foreach and just get the individual <output> directly:

var outputelement = rootelement.elements("output")
                               .firstordefault(e => (string)e.attribute("id") == "1"));


i would recommend using some xpath to select nodes you need:

foreach (xelement path in root.xpathselectelements("/output/path[../@id=1]"))
    string value = path.value;

indeed, sometimes xpath lets you write more readable and maintanable code. you just use some expression that replaces several linq-to-xml statements.

Related Query

More Query from same tag