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:
<?xml version="1.0" encoding="utf-16"?>
<text>
h
hkj
</text>
...in both text boxes but I want individual parts to go into each file.
This is the content inside the file:
<test>
//gibberish text :)
h
hkj
</test>
And this is the code for the XML:
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();
}