Hey
I want to read an xml-file and put it directly into a text box (multi lined).
Here is the Xml-file, source code and the output.
Xml-file
<?xml version="1.0"?>
<Networks>
<NW Alias="Alias">
<NWDevice Type="Coordinator" Mac="0013A20046666666" Version="Z3.2.6666 1035 N" Hardware="RM015_LOG">
<Sensor Type="Humidity" Key="1101">
</Sensor>
<Sensor Type="Humidity" Key="1102">
<Line MeasureTime="100" fromValue="60" toValue="70" Period="200"/>
<Line MeasureTime="15" fromValue="30" toValue="50" Period="30"/>
</Sensor>
<Sensor Type="Temperature" Key="1001">
<Line MeasureTime="1" fromValue="20" toValue="30" Period="3000"/>
</Sensor>
<Sensor Type="CO2" Key="1601">
<Line MeasureTime="15" fromValue="300" toValue="400" Period="45"/>
</Sensor>
</NWDevice>
</Networks>
The code:
StreamReader reader = new StreamReader(sFileName);
while (Convert.ToBoolean(reader.Read()))
{
sLine = reader.ReadLine();
if (sLine == null)
{
break;
}
txtXmlEditor.Text += sLine;
txtXmlEditor.Text += Environment.NewLine;
}
The Output:
Here you find the problem, At places there is no beginning '<' and there are places with to many spaces between the text. I want to work with so few as possible if structures.
?xml version="1.0"?>
Networks>
NW Alias="Alias">
<NWDevice Type="Coordinator" Mac="0013A20046666666" Version="Z3.2.6666 1035 N" Hardware="RM015_LOG">
<Sensor Type="Humidity" Key="1101">
</Sensor>
<Sensor Type="Humidity" Key="1102">
<Line MeasureTime="100" fromValue="60" toValue="70" Period="200"/>
<Line MeasureTime="15" fromValue="30" toValue="50" Period="30"/>
</Sensor>
<Sensor Type="Temperature" Key="1001">
<Line MeasureTime="1" fromValue="20"
toValue="30" Period="3000"/>
</Sensor>
<Sensor Type="CO2" Key="1601">
<Line MeasureTime="15" fromValue="300" toValue="400" Period="45"/>
</Sensor>
</NWDevice>
/NW>
/Networks>
PS. Sorry for my bad English.