Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Xml;
- namespace XmlParser
- {
- class Program
- {
- static void Main(string[] args)
- {
- if (args.Length < 1)
- {
- Console.WriteLine("Please provide the path to the XML file as a command-line argument.");
- return;
- }
- string filePath = args[0];
- int count = ParseXmlStream(filePath);
- Console.WriteLine("count = " + count);
- }
- private static int ParseXmlStream(string filePath)
- {
- int count = 0;
- using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- using (XmlReader reader = XmlReader.Create(fileStream))
- {
- while (reader.Read())
- {
- if (reader.NodeType == XmlNodeType.Element && reader.Name == "location")
- {
- string locationData = reader.ReadElementContentAsString();
- if (locationData.Contains("Africa"))
- {
- count++;
- }
- }
- }
- }
- return count;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement