Hello, I have a file I saved as an XML file and want different parts of the file to display in two text boxes. What is happening is the whole content of the file displays in a textbox as:
...in both text boxes but I want individual parts to go into each file.Code:<?xml version="1.0" encoding="utf-16"?> <text> h hkj </text>
This is the content inside the file:
And this is the code for the XML:Code:<test> //gibberish text :) h hkj </test>
Code:StringBuilder output = new StringBuilder(); // Create an XmlReader using (XmlTextReader xmlString = new XmlTextReader("C:\\fileLocation.xml")) { XmlWriterSettings ws = new XmlWriterSettings(); ws.Indent = true; using (XmlWriter writer = XmlWriter.Create(output, ws)) { // Parse the file and display each of the nodes. while (xmlString.Read()) { switch (xmlString.NodeType) { case XmlNodeType.Element: writer.WriteStartElement(xmlString.Name); break; case XmlNodeType.Text: writer.WriteString(xmlString.Value); break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: writer.WriteProcessingInstruction(xmlString.Name, xmlString.Value); break; case XmlNodeType.Comment: writer.WriteComment(xmlString.Value); break; case XmlNodeType.EndElement: writer.WriteFullEndElement(); break; } } } } textBox1.Text = output.ToString(); textBox2.Text = output.ToString(); }




Reply With Quote
