Skip to content

Instantly share code, notes, and snippets.

@neon-sunset
Last active May 7, 2024 09:35
Show Gist options
  • Save neon-sunset/6ba67f23e58afdb80f6be868953a5ee4 to your computer and use it in GitHub Desktop.
Save neon-sunset/6ba67f23e58afdb80f6be868953a5ee4 to your computer and use it in GitHub Desktop.
XML Parse
using System.Xml;
var count = 0;
using var file = File.OpenRead(args[0]);
using var reader = XmlReader.Create(file);
while (reader.Read())
{
if (reader is { NodeType: XmlNodeType.Element, Name: "location" })
{
var locationData = reader.ReadElementContentAsString();
if (locationData.Contains("Africa"))
{
count++;
}
}
}
Console.WriteLine($"count = {count}");
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
<OptimizationPreference>Speed</OptimizationPreference>
</PropertyGroup>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment