score:1
Accepted answer
var products = onix.descendants().where(m => m.name.localname == "product").tolist();
foreach (var p in products)
{
var title = p.descendants().where(m => m.name.localname == "title")
.descendants()
.first(m => m.name.localname == "titletype" && m.value == "01")
.parent
.descendants()
.first(m => m.name.localname == "titletext")
.value;
}
score:0
xdocument doc = xdocument.load(fs);
var products= from elements in doc.elements("onixmessage").elements("product");
foreach (var p in products)
{
var title = (from items in p.elements("title")
where items.element("titletype").value == "01"
select items.element("titletext").value).firstordefault();
}
Source: stackoverflow.com
Related Query
- Exception querying XML using linq
- Querying xml child elements with prefixed namespace using LINQ to XML
- Querying XML with LINQ and using null in place of a particular xml attribute if it does not exist
- Querying XML document using Linq
- Querying an XML File using LINQ
- Nested querying a xml document using LINQ in c#
- Querying an Xml Document for elements using Linq
- Querying XML attributes using LINQ
- Error on querying element using LINQ to XML
- Null reference Exception when trying to parse XML to object List using LINQ to XML
- Querying the nested xml using linq by specifying attribute value
- Sequence contains no elements exception in linq without even using Single
- Empty namespace using Linq Xml
- Reading XML using XDocument & Linq - check if element is NULL?
- Linq to Xml : Exception -The ' ' character, hexadecimal value 0x20, cannot be included in a name
- Mocking Delegate.Invoke() using Moq throws InvalidCast exception in LINQ
- Update XML with C# using Linq
- How to get elements by name in XML using LINQ
- Exception when using LINQ SUM
- add data to existing xml file using linq
- C# check an element exists while using LINQ to XML
- How to properly search xml document using LINQ C#
- read xml file using linq
- how to add/insert conditional node into XML using linq to XML
- Compare two xml and print the difference using LINQ
- Generate xml using LINQ to XML
- Extract data from a XML string using linq vs xmlDocument
- how to compare 2 XML using LINQ in C#
- How to read XML file using System.IO.Stream with LINQ
- Querying elastic search with linq using NEST
More Query from same tag
- Get all the child details in a xml?
- How to Write Trigger(on after insert) to Delete all Rows in Table Except Last Two Rows?
- 'Invoke' node is not supported in LINQ when nesting Expression Functions
- Equivalent of outer join with non-equals predicate in Linq
- How to change all values in a Dictionary<string, bool>?
- Group by weeks and dates EF in descending order
- c# find item in list returned by LINQ query and compare its value with another item in list
- Can we display linq result in view without using model
- GROUP BY in datatable on two columns with sum of third column using LINQ
- Linq return null for no results
- Iterate through LINQ AnonymousType object
- Separating the column values of DataTable using LINQ
- error in fetching first element from collection
- How to get required collection in my LINQ
- asp.net c#: Where clause gets bypassed with OR condition in LINQ
- Why does Linq not have Head and Tail?
- Manipulating variable type within LINQ expression
- WHERE clause in LINQ statement that pulls specific match or everything if no match found
- Initialising a new Dictionary with a List of keys
- MVC3 error when passing a model from controller to view while using a viewModel
- Select N to N rows from database using LINQ
- Checking Possible Nulls Linq Query
- LINQ Join (Left Outer) with Take(1)
- Linq - Retrieve value from a linked linked table
- Queries with local collections are not supported LINQ
- Custom sort logic in OrderBy using LINQ
- Consolidating a datatable into a more readable format: C#, Entity Framework
- Sort or Order a List of strings containing a specific word with LINQ
- Generics - get properties LINQ
- Get subset of employees based on parameters