Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

xml reader attributes

// Get Xml node attribute keys and values
static IEnumerable<(string key, string value)> GetNodeAttributes(XmlReader reader)
{
    for (int i = 0; i < reader.AttributeCount; i++)
    {
        reader.MoveToAttribute(i);
        yield return (reader.Name, reader.Value);
    }
}

// This can be used with a Linq selector
//to retrieve specific value from the attributes
static string GetAttributeValue(this IEnumerable<(string key, string value)> attributes, string attribute) =>
    attributes.Where(x => x.key == attribute).ToList()[0].value;

// Combine these methods like so to get a attribute neatly.
string value = GetNodeAttributes(reader).GetAttributeValue("name");
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# read key without writing 
Csharp :: asp.net core user.identity.name is null 
Csharp :: netmath 
Csharp :: C# JOSN Array Conversion 
Csharp :: Garbage collect every 30 frames unity 
Csharp :: random.choice c# 
Csharp :: DefaultContractResolver .net exclude null values JsonSerializerSettings ContractResolver DefaultContractResolver 
Csharp :: range to 01 
Csharp :: how to handle array getter setter in c# of string type 
Csharp :: difference between all logging framework .NET Core? 
Csharp :: Set property of control on form by name 
Csharp :: como ordenar dados na gridview c# 
Csharp :: visual studio private field underscore 
Csharp :: How to get 4 end len in string c# 
Csharp :: unity run all interfaces 
Csharp :: c sharp tenery operator with callin gmethods 
Csharp :: C# Check if variables are equal 
Csharp :: internet connection sharing 
Csharp :: REMOVE BOTTOM TAB XAMARIN FORMS 
Csharp :: C# read GroupComponent Or PartComponent using regex 
Csharp :: c# ensure static constructor is called 
Csharp :: .net SaveChanges vs update difference 
Csharp :: C# if...else if Statement 
Csharp :: unity having virtual start 
Csharp :: Web forms switch page 
Csharp :: calculate 01 with min max value 
Csharp :: copy properties from two subclasses c# 
Csharp :: c# functions 
Csharp :: c# project 
Csharp :: qrcode c# 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =