static void Main(string[] args) { XmlReader reader = XmlReader.Create(FILENAME); reader.ReadToFollowing("SubNetwork", "generic.xsd"); Network.network.name = reader.GetAttribute("id"); Network.network.subnetworks = new List <SubNetwork>(); reader.ReadToFollowing("SubNetwork", "generic.xsd"); SubNetwork subNetWork = new SubNetwork(); Network.network.subnetworks.Add(subNetWork); subNetWork.name = reader.GetAttribute("id"); subNetWork.sites = new List <Sites>(); Sites newSite = null; while (!reader.EOF) { if (!reader.Name.Contains("VsDataContainer")) { reader.ReadToFollowing("VsDataContainer", "generic.xsd"); } if (!reader.EOF) { XElement vsDataContainer = (XElement)XElement.ReadFrom(reader); XElement vsDataENodeBFunction = vsDataContainer.Descendants().Where(a => a.Name.LocalName == "vsDataENodeBFunction").FirstOrDefault(); if (vsDataENodeBFunction != null) { newSite = new Sites(); subNetWork.sites.Add(newSite); XElement eNBId = vsDataContainer.Descendants().Where(a => a.Name.LocalName == "eNBId").FirstOrDefault(); if (eNBId != null) { newSite.eNBId = (int)eNBId; } } XElement vsDataEUtranCellFDD = vsDataContainer.Descendants().Where(a => (a.Name.LocalName == "vsDataType") && ((string)a == "vsDataEUtranCellFDD")).FirstOrDefault(); if (vsDataEUtranCellFDD != null) { CellName newCellName = new CellName() { id = (string)vsDataContainer.Attribute("id"), earfcndl = (int)vsDataContainer.Descendants().Where(a => a.Name.LocalName == "earfcndl").FirstOrDefault(), earfcnul = (int)vsDataContainer.Descendants().Where(a => a.Name.LocalName == "earfcnul").FirstOrDefault() }; if (newSite.cellName == null) { newSite.cellName = new List <CellName>(); } newSite.cellName.Add(newCellName); } } } }
static void Main(string[] args) { XmlReaderSettings settings = new XmlReaderSettings() { IgnoreWhitespace = true }; XmlReader reader = XmlReader.Create(FILENAME, settings); reader.ReadToFollowing("SubNetwork", "generic.xsd"); Network.network.name = reader.GetAttribute("id"); Network.network.subnetworks = new List <SubNetwork>(); string xnNameSpace = reader.LookupNamespace("xn"); reader.ReadToFollowing("SubNetwork", xnNameSpace); Sites newSite = null; SubNetwork subNetWork = null; Boolean endElement = false; State state = State.GET_SUBNETWORK; while (!reader.EOF) { switch (state) { case State.GET_SUBNETWORK: if (reader.Name != "xn:SubNetwork") { reader.ReadToFollowing("SubNetwork", xnNameSpace); } if (!reader.EOF) { subNetWork = new SubNetwork(); Network.network.subnetworks.Add(subNetWork); subNetWork.name = reader.GetAttribute("id"); subNetWork.sites = new List <Sites>(); state = State.GET_MECONTEXT; } break; case State.GET_MECONTEXT: if (reader.Name != "xn:MeContext") { if (reader.NodeType == XmlNodeType.EndElement) { endElement = true; state = State.GET_SUBNETWORK; } else { endElement = false; reader.ReadToFollowing("MeContext", xnNameSpace); } } if (!reader.EOF && !endElement) { state = State.GET_CONTAINERS; reader.ReadToFollowing("VsDataContainer", xnNameSpace); } break; case State.GET_CONTAINERS: if (!reader.EOF) { switch (reader.NodeType) { case XmlNodeType.EndElement: state = State.GET_SUBNETWORK; break; case XmlNodeType.Text: string text = reader.ReadContentAsString(); break; case XmlNodeType.Element: string elementName = reader.Name; XElement element = (XElement)XElement.ReadFrom(reader); if (elementName == "xn:VsDataContainer") { XElement vsDataENodeBFunction = element.Descendants().Where(a => a.Name.LocalName == "vsDataENodeBFunction").FirstOrDefault(); if (vsDataENodeBFunction != null) { newSite = new Sites(); subNetWork.sites.Add(newSite); XElement eNBId = element.Descendants().Where(a => a.Name.LocalName == "eNBId").FirstOrDefault(); if (eNBId != null) { newSite.eNBId = (int)eNBId; } } XElement vsDataEUtranCellFDD = element.Descendants().Where(a => (a.Name.LocalName == "vsDataType") && ((string)a == "vsDataEUtranCellFDD")).FirstOrDefault(); if (vsDataEUtranCellFDD != null) { CellName newCellName = new CellName() { id = (string)element.Attribute("id"), earfcndl = (int)element.Descendants().Where(a => a.Name.LocalName == "earfcndl").FirstOrDefault(), earfcnul = (int)element.Descendants().Where(a => a.Name.LocalName == "earfcnul").FirstOrDefault() }; if (newSite.cellName == null) { newSite.cellName = new List <CellName>(); } newSite.cellName.Add(newCellName); } } break; default: Console.WriteLine("Unexpected Results"); string elementText = reader.ReadContentAsString(); Console.ReadLine(); break; } } break; } } }