public xsdItem PrevSibling() { if (prevSiblingOk) { return(_prevSibling); } _prevSibling = FindPrevSibling(); prevSiblingOk = true; return(_prevSibling); }
public xsdItem NextSibling() { if (nextSiblingOk) { return(_nextSibling); } _nextSibling = FindNextSibling(); nextSiblingOk = true; return(_nextSibling); }
public int NodeLevel() { int sOut = 1; xsdItem xP = Parent; while (xP != null) { sOut++; xP = xP.Parent; } return(sOut); }
public string Level() { string sOut = ""; xsdItem xP = Parent; while (xP != null) { sOut += "\t"; xP = xP.Parent; } return(sOut); }
private string BuildXML() { StopStr = new List <String>(); string sIg = "state;magnitude_status;math_function;origin;time;width;normal_status;other_reference_ranges;normal_range;null_flavour;terminology_id;mappings;links;language;encoding;provider;subject;other_participations;context;setting;uid;composer;territory;category;context;Любое_событие_as_Interval_Event"; String[] stops = sIg.ToLower().Split(';'); foreach (string s in stops) { StopStr.Add(s); } XmlDocument xDoc = new XmlDocument(); string sXSD = File.ReadAllText(txtXSD.Text); // patch Factor problem sXSD = sXSD.Replace("Провоцирующий_fslash_купирующий_фактор", "Провоцирующий_фактор"); sXSD = sXSD.Replace("<", "_меньше_"); sXSD = sXSD.Replace(">", "_больше_"); xDoc.LoadXml(sXSD); nsmgr = new XmlNamespaceManager(xDoc.NameTable); nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); //nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); StringBuilder sb = new StringBuilder(); xsdItem root = new xsdItem(); XmlNodeList rootElements = xDoc.LastChild.ChildNodes; XmlElement rootEl; foreach (XmlNode node in rootElements) { if (node.Name == "xs:element") { rootEl = (XmlElement)node; Name = rootEl.GetAttribute("name"); root.Name = Name; root.Type = "root"; readChild(root, rootEl); } } root.RestoreParent(); using (var writer = new System.IO.StreamWriter(txtXSD.Text + ".map")) { var serializer = new XmlSerializer(root.GetType()); serializer.Serialize(writer, root); writer.Flush(); } string sOut; string testName; //if (TestCount > 0) //{ FileInfo fi = new FileInfo(txtXSD.Text); testName = fi.DirectoryName; for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 5; j++) { root.SetGenPercent((short)(i * 2)); sOut = root.Generate(null).ToString(); File.WriteAllText(testName + "\\test_" + i.ToString() + "_" + j.ToString() + ".xml", sOut); } } //} root.SetGenPercent(0); sOut = root.Generate(null).ToString(); return(sOut); }
private void readChild(xsdItem xsd, XmlElement el) { XmlNodeList ct = el.SelectNodes("./xs:complexType", nsmgr); foreach (XmlNode node in ct) { XmlElement el2 = (XmlElement)node; XmlNodeList sq = el2.SelectNodes("./xs:sequence", nsmgr); foreach (XmlNode node2 in sq) { XmlElement el3 = (XmlElement)node2; XmlNodeList children = el3.SelectNodes("./xs:element", nsmgr); foreach (XmlNode node3 in children) { XmlElement el4 = (XmlElement)node3; xsdItem xsdChild = new xsdItem(); try { xsdChild.Name = el4.GetAttribute("name"); } catch { } if (xsdChild.Name != "") { if (!StopStr.Contains(xsdChild.Name.ToLower())) { try { xsdChild.Type = el4.GetAttribute("type"); } catch { xsdChild.Type = ""; } if (xsdChild.Type == "") { XmlNodeList restricts = el4.SelectNodes("./xs:simpleType/xs:restriction", nsmgr); if (restricts != null && restricts.Count > 0) { XmlElement r = (XmlElement)restricts[0]; try { xsdChild.Type = r.GetAttribute("base"); } catch { xsdChild.Type = ""; } XmlNodeList pattern = r.SelectNodes("xs:pattern", nsmgr); foreach (XmlNode pn in pattern) { XmlElement p = (XmlElement)pn; try { xsdChild.Patterns.Add(p.GetAttribute("value")); } catch { } } XmlNodeList ens = r.SelectNodes("xs:enumeration", nsmgr); if (ens.Count > 0) { string R = ""; foreach (XmlNode pn in ens) { if (R != "") { R += ";"; } XmlElement p = (XmlElement)pn; try { R += p.GetAttribute("value"); } catch { } } if (R != "") { xsdChild.Restrictions = R; } } } } try { xsdChild.oMin = el4.GetAttribute("minOccurs"); } catch { xsdChild.oMin = "0"; } if (xsdChild.oMin == "") { xsdChild.oMin = "0"; } try { xsdChild.oMax = el4.GetAttribute("maxOccurs"); } catch { xsdChild.oMax = "1"; } if (xsdChild.oMax == "") { xsdChild.oMax = "1"; } try { xsdChild.Fixed = el4.GetAttribute("fixed"); } catch { xsdChild.Fixed = ""; } if (xsdChild.Name.ToLower() == "defining_code") { XmlNodeList restricts = el4.SelectNodes(".//xs:restriction", nsmgr); if (restricts != null && restricts.Count > 0) { xsdChild.Restrictions = processRestrictions(restricts[0].InnerXml); if (xsdChild.Restrictions != null && xsdChild.Restrictions != "") { xsd.Children.Add(xsdChild); } } else { XmlNodeList seq = el4.SelectNodes("./xs:complexType/xs:sequence", nsmgr); if (seq != null && seq.Count > 0) { xsdChild.Restrictions = processRestrictions(seq[0].InnerXml); if (xsdChild.Restrictions != null && xsdChild.Restrictions != "") { xsd.Children.Add(xsdChild); } } } } else { xsd.Children.Add(xsdChild); readChild(xsdChild, el4); } } } } children = el3.SelectNodes("./xs:choice/xs:element", nsmgr); foreach (XmlNode node3 in children) { XmlElement el4 = (XmlElement)node3; xsdItem xsdChild = new xsdItem(); try { xsdChild.Name = el4.GetAttribute("name"); } catch { } if (xsdChild.Name != "") { if (!StopStr.Contains(xsdChild.Name.ToLower())) { try { xsdChild.Type = el4.GetAttribute("type"); } catch { xsdChild.Type = ""; } if (xsdChild.Type == "") { XmlNodeList restricts = el4.SelectNodes("./xs:simpleType/xs:restriction", nsmgr); if (restricts != null && restricts.Count > 0) { XmlElement r = (XmlElement)restricts[0]; try { xsdChild.Type = r.GetAttribute("base"); } catch { xsdChild.Type = ""; } } } try { xsdChild.oMin = el4.GetAttribute("minOccurs"); } catch { xsdChild.oMin = "0"; } if (xsdChild.oMin == "") { xsdChild.oMin = "0"; } try { xsdChild.oMax = el4.GetAttribute("maxOccurs"); } catch { xsdChild.oMax = "1"; } if (xsdChild.oMax == "") { xsdChild.oMax = "1"; } try { xsdChild.Fixed = el4.GetAttribute("fixed"); } catch { } if (xsdChild.Name.ToLower() == "defining_code") { XmlNodeList restricts = el4.SelectNodes(".//xs:restriction", nsmgr); if (restricts != null && restricts.Count > 0) { xsdChild.Restrictions = processRestrictions(restricts[0].InnerXml); xsd.Choice.Add(xsdChild); } } else { xsd.Choice.Add(xsdChild); readChild(xsdChild, el4); } } } } } } }