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();
Source: stackoverflow.com
Related Query
- IEnumerable<XAttribute> is returning Null, Needs to Return Attribute Value
- Return null instead default value in LINQ
- LINQ - Returning value of a property of an object that is not null
- Visual Studio assumes return value from FirstOrDefaultAsync() cannot be null
- SQL Trigger is trying to insert a null value but my C# code is passing int 300?
- default(T?) does not return null when T is a value type
- Return cell with value not null using linq - Epplus
- Need to join two strings if both contain values, or return one value if first is NULL
- Linq 2 XML not returning element based in attribute value
- returning default value if a property is null
- Returning value on null linq query
- Show some default text if return value is null or empty
- Linq query return coumn value null handle
- LINQ function to return list but compiler says function doesn't return a value on all code path
- How to search a class within a namespace by the value of an attribute and return an object?
- Simple Linq expression Sum - Not returning null value for empty list
- Error 1 'Form1.CountWordsInstances(string, string)': not all code paths return a value
- Return value of stored procedure is correct but column values are all NULL
- Return a value or null using LINQ in one line?
- Linq to XML Find a an attribute and return seperate attribute value
- LINQ returning Null while same query when write in SQL return result
- c# Null value returning from Linq
- How to return null value when using CopyToDataTable() LINQ extension method
- How do I return list of elements by attribute value
- Return value or null, without null reference exception linq
- Iterate through elements of the same name and return attribute by another attribute value
- How to return all values of a column as null except one column value in LINQ?
- Select Linq statement needs to return 0 if either item is null
- where Clause in Asp.net is returning null exception in the code below
- Linq query returning null when trying to pass a column value from list object
More Query from same tag
- How to get the closest number from a List<int> with LINQ?
- LINQ datarow string to array and then into to string list
- AutoMapper Project().To<T> and reusable lambda expressions
- Filter an itemssource of a listbox
- How do I outer join and group by in Entity framework Linq?
- Calculating average for last X number of records
- Combining Filtering and string concatenation with DRY
- Error Linq to Entities Datetime
- Explain line of code specifically where it says t
- Convert SQL query with multiple GroupBy columns to LINQ
- EF 6 vs EF 5 relative performance issue when deploying to IIS8
- Linq reducing one-to-many relationship to one-to-one
- Is there a conflict when using Data Caching and Lazy loading?
- Iterate through XML element[n] childs
- This is a linq sanity check
- C# compiler error CS1963: "An expression tree may not contain a dynamic operation"
- Get index value of list on condition in C#
- Getting an element tree broken down from an XML
- Traversing through Linq Result gives Object Reference Not Set to Instance
- multi join linq and group by year and month
- Using my own method with LINQ to Entities
- Linq query: MAX in WHERE
- How to remove duplicates from an Array using LINQ
- not getting child category when returning parent category in linq entity framework
- linq to sql return only match based on ID
- Search In claims
- The FunctionImport 'GetEmployee' could not be found in the container 'CtxDb'
- How to convert an MySql query to Linq with count and attributes
- Conditioning LINQ Query
- Build expression on DataTable, design suggestion?