private void SubmitButton_Click(object sender, EventArgs e) { try { string text = ""; if (this.FileName != null || this.FileName != "") { text = File.ReadAllText(this.FileName); } else { string fileName = FileNameTextBox.Text; if (validFileName(fileName)) { } else { text = File.ReadAllText(fileName); } } int size = -1; this.XmlText = text; size = text.Length; FullXMLBox.ResetText(); FullXMLBox.AppendText(text); XPathQueryResultTextBox.ResetText(); XPathQueryResultTextBox.AppendText(text); XPathDocument myXPathDoc = new XPathDocument(this.FileName); applyTransformations(myXPathDoc); resetStatusStrip(); } catch (Exception ex) { showStatusError(ex.StackTrace); } }
private void applyButtonClick(object sender, EventArgs e) { try { if (!validXml()) { MessageBox.Show("XML Input is not well formed"); } else { string xpath = this.xPath.Text; if (xpath == null || xpath == "") { XPathQueryResultTextBox.ResetText(); XPathQueryResultTextBox.AppendText(this.XmlText); resetStatusStrip(); return; } else { XmlDocument doc = new XmlDocument(); doc.LoadXml(this.XmlText); //XmlNodeList nodesList = doc.DocumentElement.SelectNodes(xpath); XPathNavigator nav = doc.CreateNavigator(); XPathExpression expr = nav.Compile(xpath); XPathNodeIterator nodes = nav.Select(xpath); //Remove text before adding XPathQueryResultTextBox.ResetText(); while (nodes.MoveNext()) { XPathNavigator node = nodes.Current.Clone(); //next level of check even though text is reset before if (XPathQueryResultTextBox.Text.Length == 0) { XPathQueryResultTextBox.Text = node.OuterXml; } else { XPathQueryResultTextBox.AppendText(Environment.NewLine); XPathQueryResultTextBox.AppendText(node.OuterXml); } } //XPathQueryResultTextBox.ResetText(); //XPathQueryResultTextBox.AppendText(XmlNodeListToString(nodesList)); resetStatusStrip(); } } } catch (Exception ex) { showStatusError(ex.Message); } }