score:2
Accepted answer
I corrected your first attempt (LINQ). It returns first <PName type="Patient">
from xml in question.
IEnumerable<XElement> tests =
from el in root.Element("PList").Elements("PName")
let c = el.Descendants("classification")
where c.Where(x => x.Attribute("classification").Value == "paymenttype"
&& x.Attribute("category").Value == "Wallet").Any()
select el;
Then you can iterate tests
and extract what you want.
foreach (var el in tests)
{
Console.WriteLine(
el.Element("properties")
.Element("PName")
.Attribute("title")
.Value);
}
I also corrected your second attempt (XPath). It will return title value of <PName title="Joe Beom" PId="1234">
.
var query = @"//PName[Details/classification[@classification='paymenttype' and @category='Wallet']]/@title";
foreach (XmlNode n in docs.SelectNodes(query))
{
Console.WriteLine(n.Value);
}
Source: stackoverflow.com
Related Articles
- Read multiple nodes based on Condition
- how to get child single records based on multiple condition having multiple child nodes c# linq or xpath
- How can i copy data table records of different field name based on mapping list evaluating condition on source data table?
- Delete records with multiple ids based on condition
- How to do condition statement in LINQ based on code variables?
- linq query to get multiple datatable from dataset based on some condition
- How to merge multiple lists based on a condition using LINQ
- How to write C# LINQ code to select based on condition
- Replace a list item value with another list item value based on multiple condition
- Select multiple records based on list of Id's with linq
- Remove item from list based on condition
- LINQ: differences between single Where with multiple conditions and consecutive Wheres with single condition
- How do I remove items from generic list, based on multiple conditions and using linq
- Remove duplicates from list based on multiple fields or columns
- Does this LINQ code perform multiple lookups on the original data?
- How to find duplicate items based on multiple values using LINQ?
- Order by descending based on condition
- Split a collection into parts based on condition with LINQ?
- How to reuse a linq expression for 'Where' when using multiple source tables
- Remove Duplicate item from list based on condition
- Split collection into objects based on condition and occurrence
- LINQ Source Code Available
- how to take 100 records from linq query based on a condition
- multiple orderby in this linq code
- Read all XML child nodes of each specific node
- Delete multiple XML nodes in C# using Linq
- How to store and lookup data, based on multiple xml attributes?
- LINQ query on an object list to get distribution based on multiple fields
- .NET 4 Code Contracts: "requires unproven: source != null"
- LInq left join with multiple condition in on clause
- Linq query to take the value from Array with matching sub string value
- Bool to int in a LINQ group sum query
- Check specific values in an array
- How do you overload Linq's Where clause to accept SqlBoolean?
- Cannot fire itemcommand event asp.net
- Is there a suggested pattern for using LINQ between the Model & DataAccess Layers in a DDD based Layered Architecture
- Linq not adding data to table, using InsertOnSubmit() & SubmitChanges()
- LINQ, Left Join, Only Get where null in join table
- Embed a test for null in a single LINQ expression
- How to Optmize a multiple if else with LINQ
- VS2015 LINQ in debugger watch window
- Entity Framework with SQL Server 2000 (APPLY Operator) issue
- Facing issue with filtering values at API using GroupBy
- Error in a LINQ query
- entity cannot be constructed in a LINQ to Entities query
- Linq - how to write group by query to get quantity of each product
- Why is the Linq-to-Objects sum of a sequence of nullables itself nullable?
- Do i really need use AsQueryable() on collection?
- How to group by items that can grow?
- Need help refactoring a LINQ statement with a Group By clause?