Home > DeveloperSection > Forums > how to retrieve attributes using LINQ
Ashish Pandey

Total Post:128

Points:898
Posted on    December-09-2013 11:35 PM

 XML XML 
Ratings:


 1 Reply(s)
 1028  View(s)
Rate this:

I am trying to get ALL attributes from "server" below:

This is the XML file(partial):

<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<server xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" noNamespaceSchemaLocation="udsServerInfo.xsd" id="57672acc-4ba7-4876-811a-1629eca853ed" productPath="C:\Tools\UDS\udsServerInfo\" osActivated="true">

  <networkAdapters>

Here is the code which returns NULL for "server":

    var server = (from node in doc.Attributes("server")

                       select node);

I am able to get all networkAdapters by calling doc.Descendants("networkAdapter") but haven't figured out how to obtain the attributes .

Thank you



ezra heywood
ezra heywood

Total Post:145

Points:1019
Posted on    December-10-2013 12:07 AM

Hi Ashish,

Try this (assuming doc is an XDocument):

var attributes = doc.Descendants("server").Attributes();

or

var id = doc.Descendants("server").Attributes("id");

or

var productPath = doc.Descendants("server").Attributes("productPath");

Don't want to miss updates? Please click the below button!

Follow MindStick