// генерация по готовой структуре public string BuildXML(xsdItem newRoot, string GenPaths) { root = newRoot; root.RestoreParent(); string sOut; string testName; List <string> Paths = null; testName = OutFolder + "\\" + root.Name + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xml"; if (GenPaths == "") { sOut = root.Generate(null).ToString(); } else { Paths = new List <string>(); string[] s = GenPaths.Split('\r'); foreach (string s1 in s) { if (s1.Length > 1) { Paths.Add(s1.Replace("\n", "")); } } sOut = root.GeneratePaths(null, Paths).ToString(); } File.WriteAllText(testName, sOut); return(testName); // sOut; }
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 void LoadTree() { tv.Nodes.Clear(); xsdItem t = xb.root; TreeNode n = new TreeNode(); n.Text = NodeName(t); n.Tag = t; n.ImageIndex = 4; tv.Nodes.Add(n); AddChildren(n, t); }
private void chkSkip_CheckedChanged(object sender, EventArgs e) { if (InAfterSelect) { return; } if (tv.SelectedNode == null) { return; } xsdItem x = (xsdItem)tv.SelectedNode.Tag; x.Skip = chkSkip.Checked; UpdateNode(tv.SelectedNode); }
private void numGenPrc_ValueChanged(object sender, EventArgs e) { if (InAfterSelect) { return; } if (tv.SelectedNode == null) { return; } xsdItem x = (xsdItem)tv.SelectedNode.Tag; x.GenPercent = (short)numGenPrc.Value; UpdateNode(tv.SelectedNode); }
private void txtMin_TextChanged(object sender, EventArgs e) { if (InAfterSelect) { return; } if (tv.SelectedNode == null) { return; } xsdItem x = (xsdItem)tv.SelectedNode.Tag; if (IsNumeric(txtMin.Text) || txtMin.Text == "") { x.oMin = txtMin.Text; UpdateNode(tv.SelectedNode); } }
private void AddChildren(TreeNode parent, xsdItem x) { foreach (xsdItem t in x.Children) { TreeNode n = new TreeNode(); n.Text = NodeName(t); if (t.Name == "defining_code") { n.ImageIndex = 5; } else if (t.Skip) { n.ImageIndex = 3; } else { n.ImageIndex = 1; } n.Tag = t; parent.Nodes.Add(n); AddChildren(n, t); } foreach (xsdItem t in x.Choice) { TreeNode n = new TreeNode(); n.Text = NodeName(t); if (t.Name == "defining_code") { n.ImageIndex = 5; } else if (t.Skip) { n.ImageIndex = 3; } else { n.ImageIndex = 2; } n.Tag = t; parent.Nodes.Add(n); AddChildren(n, t); } }
// загрузка структуры данных из файла XML public void LoadXSD(string newXSDPath) { XSDPath = newXSDPath; XmlDocument xDoc = new XmlDocument(); string sXSD = File.ReadAllText(XSDPath); // 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"); StringBuilder sb = new StringBuilder(); root = new xsdItem(); XmlNodeList rootElements = xDoc.LastChild.ChildNodes; XmlElement rootEl; foreach (XmlNode node in rootElements) { if (node.Name == "xs:element") { rootEl = (XmlElement)node; string Name = rootEl.GetAttribute("name"); root.Name = Name; root.Type = "root"; root.oMax = "1"; root.oMin = "1"; readChild(root, rootEl); } } root.RestoreParent(); }
private void MarkForGenerate(xsdItem x, string gPath) { if (x.NeedGenerateItem == false) { if (x.Finder(gPath)) { x.NeedGenerateItem = true; System.Diagnostics.Debug.Print("Mark: " + x.FullPath() + " for " + gPath); x.NeedAllParents(); } } foreach (xsdItem i in x.Children) { i.MarkForGenerate(i, gPath); } foreach (xsdItem i in x.Choice) { i.MarkForGenerate(i, gPath); } }
private void tv_AfterSelect(object sender, TreeViewEventArgs e) { InAfterSelect = true; xsdItem x = (xsdItem)e.Node.Tag; txtName.Text = x.Name; txtType.Text = x.Type; txtFixed.Text = x.Fixed + x.Restrictions; txtMin.Text = x.oMin; txtMax.Text = x.oMax; numGenPrc.Value = x.GenPercent; if (x.Skip) { chkSkip.Checked = true; } else { chkSkip.Checked = false; } InAfterSelect = false; }
private string NodeName(xsdItem t) { String Flags = ""; { Flags += "["; if (t.oMin != null && t.oMin != "") { Flags += t.oMin; } else { Flags += "0"; } Flags += ".."; if (t.oMax != null && t.oMax != "") { Flags += t.oMax.Replace("unbounded", "*"); } else { Flags += "1"; } Flags += "]"; } string sName = t.Name + " " + Flags; if (t.Type != null && t.Type != "") { sName += " (" + t.Type + ")"; } if (t.Fixed != "") { sName += " ='" + t.Fixed + "'"; } return(sName); }
// чтение структуры 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); } } } } // обработка choice варианта 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"; } 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); } } } } } } }