score:0

Accepted answer

this may help you. everything you wrote that code was right, you just rather use main.element("network").attributes() than main.attributes()

ienumerable<xattribute> successattributes =
                 from attribute in main.element("network").attributes()
                 where attribute.name.localname == "nid"
                 select attribute;

on behalf of this issue i wrote the below sample program which will yield the expected nid value

string strval = "<server><network nid=\"43d5377-0dcd-40e6-b95c-8ee980b1e248\"/><client_group id=\"20\">963440d0-96dc-46a4-a54d-7251a65f585f</client_group><clientid id=\"20\">3fc8ffa1-c16b-4d7b-9e55-1e88dfe15277</clientid></server>";

            xelement main = xelement.load(new stringreader(strval));

            ienumerable<xattribute> successattributes =
                 from attribute in main.element("network").attributes()
                 where attribute.name.localname == "nid"
                 select attribute;

score:0

main here is the root element: <server> - which does not have a nid attribute.

you want something like:

guid nid = (guid)main.element("network").attribute("nid");

or for multiple:

guid[] arr = (from attr in main.descendentsorself().attributes("nid")
              select (guid)attr).toarray();

Related Query

More Query from same tag