private void ReadOsm(System.Xml.XmlTextReader xml) { using (var osm = xml.ReadSubtree()) { //while (osm.Read()) //{ // if (osm.NodeType == System.Xml.XmlNodeType.Element && (osm.Name == "node" || osm.Name == "way")) // { // ReadAnyOsmElement(osm); // } //} while (true) { try { bool canRead = osm.Read(); if (!canRead) { break; } if (osm.NodeType == System.Xml.XmlNodeType.Element && (osm.Name == "node" || osm.Name == "way")) { ReadAnyOsmElement(osm); } } catch (Exception e) { ConsoleWrite.Red("Error occured when reading XML-tree."); } } } }
// Die Funktionen sind aus den Folien, nicht anfassen! private List <string> ReadOsm(System.Xml.XmlTextReader xml, bool saveAll, string searchStreet) { List <string> cities = new List <string>(); using (var osm = xml.ReadSubtree()) { while (osm.Read()) { if (osm.NodeType == System.Xml.XmlNodeType.Element && (osm.Name == "node" || osm.Name == "way")) { ReadAnyOsmElement(osm, saveAll, ref cities, searchStreet); } } } return(cities); }
/// <summary> /// Reads the element content as collection. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="reader">The reader.</param> /// <returns></returns> public static System.Collections.Generic.List <T> ReadElementContentAsCollection <T>(this System.Xml.XmlReader reader) where T : class { System.Collections.Generic.List <T> result = new System.Collections.Generic.List <T>(); System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(T)); string xml = reader.ReadOuterXml(); using (System.IO.StringReader sr = new System.IO.StringReader(xml)) { using (System.Xml.XmlTextReader xmlTextReader = new System.Xml.XmlTextReader(sr)) { xmlTextReader.ReadStartElement(); while (!xmlTextReader.EOF) { if (xmlTextReader.NodeType == System.Xml.XmlNodeType.EndElement) { xmlTextReader.ReadEndElement(); continue; } T obj; if (xmlTextReader.IsEmptyElement && xmlTextReader.HasAttributes) { obj = serializer.Deserialize(xmlTextReader) as T; } else { System.Xml.XmlReader subTree = xmlTextReader.ReadSubtree(); obj = serializer.Deserialize(subTree) as T; } if (obj != null) { result.Add(obj); } if (!xmlTextReader.IsEmptyElement) { xmlTextReader.Read(); } } } } return(result); }
private static List <string> GetCitiesFromNodes(System.Xml.XmlTextReader xml, string street) { var cities = new List <string>(); using (var osm = xml.ReadSubtree()) { while (osm.Read()) { if (osm.NodeType == System.Xml.XmlNodeType.Element && (osm.Name == "node")) { var pair = GetCityAndStreet(osm); if (pair.Count == 2 && pair[1].ToLower() == street && !cities.Contains(pair[0])) { cities.Add(pair[0]); } } } } return(cities); }
private static void FillCitiesDictionary(System.Xml.XmlTextReader xml) { var streets = new List <string>(); var cities = new List <string>(); using (var osm = xml.ReadSubtree()) { while (osm.Read()) { if (osm.NodeType == System.Xml.XmlNodeType.Element && (osm.Name == "node")) { var pair = GetCityAndStreet(osm); if (pair.Count == 2) { cities.Add(pair[0]); streets.Add(pair[1].ToLower()); } } } } for (var i = 0; i < streets.Count; i++) { if (!Cities.ContainsKey(streets[i])) { Cities.Add(streets[i], new List <string> { cities[i] }); } else { if (!Cities[streets[i]].Contains(cities[i])) { Cities[streets[i]].Add(cities[i]); } } } }