private void ParsingXML_readInstance(IEnumerable <XElement> elements, ref Model mod, int depth, int flg) { int idOffset = 0; if (flg == 0) { mod.Id = depth.ToString(); } foreach (var ele in elements) { switch (ele.Name.ToString()) { case "Type": mod.Type = ele.Value; break; case "Coupling": Coupling cp = new Coupling(ele.Attribute("from").Value, ele.Attribute("fPort").Value, ele.Attribute("to").Value, ele.Attribute("tPort").Value); mod.Couplings.Add(cp); break; case "SubModel": Model temp = new Model(ele.Attribute("name").Value, "SI"); if (flg == 0) { //temp.Id = makeId(depth, idOffset); ParsingXML_readInstance(ele.Elements(), ref temp, depth + 1, flg); } mod.Instances.Add(temp); idOffset += 1; break; default: Console.WriteLine("[ERROR]----" + ele.Name); break; } } }
private void ParsingXML(IEnumerable <XElement> elements, ref Model mod, int depth) { int idOffset = 0; mod.Id = depth.ToString(); foreach (var e in elements) { switch (e.Name.ToString()) { case "Port": Port pt = new Port(e.Attribute("type").Value == "In" ? PortType.IN : PortType.OUT, e.Value); mod.Ports.Add(pt); break; case "SubModel": Model temp = new Model(e.Attribute("name").Value, "SI"); //temp.Id = makeId(depth, idOffset); ParsingXML_readInstance(e.Elements(), ref temp, depth + 1, 0); mod.Instances.Add(temp); idOffset += 1; break; case "Couplings": foreach (var ele in e.Elements()) { Coupling cp = new Coupling(ele.Attribute("from").Value, ele.Attribute("fPort").Value, ele.Attribute("to").Value, ele.Attribute("tPort").Value); mod.Couplings.Add(cp); } break; default: Console.WriteLine("[ERROR]----" + e.Name); break; } } }