public XmlReaderValidator(XmlReader subjectReader, XmlReader otherReader, string because, object[] reasonArgs) { assertion = Execute.Assertion.BecauseOf(because, reasonArgs); this.subjectReader = new XmlReaderWrapper(subjectReader); this.otherReader = new XmlReaderWrapper(otherReader); }
private IEnumerator <TNode> ReaderContainer <TNode>(IXmlNodeProcessor <TNode> processor, XmlReader reader, TNode baseNode, TNode defaultNamespace) { var wrapper = new XmlReaderWrapper(reader, UseReflection); var originalBaseUri = wrapper.BaseUri; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.DocumentType: processor.ProcessDocumentType(reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.CanResolveEntity ? null : reader.Value, String.IsNullOrWhiteSpace(reader.Value), baseNode, ref defaultNamespace); continue; case XmlNodeType.Whitespace: yield return(processor.ProcessWhitespace(wrapper, false)); continue; case XmlNodeType.SignificantWhitespace: yield return(processor.ProcessWhitespace(wrapper, true)); continue; case XmlNodeType.Text: yield return(processor.ProcessText(wrapper, false)); continue; case XmlNodeType.CDATA: yield return(processor.ProcessText(wrapper, true)); continue; case XmlNodeType.Comment: yield return(processor.ProcessComment(wrapper)); continue; case XmlNodeType.ProcessingInstruction: yield return(processor.ProcessProcessingInstruction(wrapper, defaultNamespace)); continue; case XmlNodeType.EntityReference: yield return(processor.ProcessEntityReference(wrapper)); continue; case XmlNodeType.Element: yield return(processor.ProcessElement(wrapper, baseNode, originalBaseUri, defaultNamespace, innerBaseNode => ReaderContainer(processor, reader, innerBaseNode, defaultNamespace))); continue; } if (reader.NodeType == XmlNodeType.EndElement) { break; } } }
public TNode Convert <TNode>(XmlReader reader, IXmlNodeProcessor <TNode> processor) { var wrapper = new XmlReaderWrapper(reader, UseReflection); return(processor.ProcessDocument(wrapper, documentNode => ReaderContainer(processor, reader, documentNode, default))); }
static int Main(string[] args) { if (args.Length < 4) { Console.WriteLine("./program XmlFilename StateAbreviation Latitude Longitude"); Console.WriteLine(" NOAH station information can be pulled from https://api.tidesandcurrents.noaa.gov/mdapi/prod/webapi/stations/"); return(-1); } var xmlfilename = args[0]; var stateabreviation = args[1]; var latitude = Convert.ToSingle(args[2]); var longitude = Convert.ToSingle(args[3]); var results = XmlReaderWrapper.Parse(xmlfilename, new List <XmlElement>() { new XmlElement() { Name = "station", IsResultContainer = true }, new XmlElement() { Name = "id" }, new XmlElement() { Name = "name" }, new XmlElement() { Name = "lat" }, new XmlElement() { Name = "lng" }, new XmlElement() { Name = "tidetype" }, new XmlElement() { Name = "tidal" }, new XmlElement() { Name = "state" }, new XmlElement() { Name = "timezone" } }); Console.WriteLine($"Count : {results.Count}"); var smallestDistance = Single.MaxValue; foreach (var row in results) { // only consider stations in a specific state if (!row.TryGetValue("state", out string state)) { continue; } if (!string.Equals(state, stateabreviation, StringComparison.OrdinalIgnoreCase)) { continue; } // get distance from lat/lng var distance = Single.MaxValue; if (row.TryGetValue("lat", out string lat)) { if (row.TryGetValue("lng", out string lng)) { distance = DistanceFromLatLng(latitude, longitude, Convert.ToSingle(lat), Convert.ToSingle(lng)); } } foreach (var kvp in row) { Console.Write($"{kvp.Key}:{kvp.Value} "); } Console.WriteLine($"distance:{distance}"); smallestDistance = Math.Min(distance, smallestDistance); } Console.WriteLine($"{smallestDistance}"); return(0); }