We have to write a code in C# (windows form) that loads a XML file into a richtextbox. WORKS
This is what a textfield looks like:
<Hmi.Screen.TextField Name="Text Field_1" AggregationName="ScreenItems" ID="31">
<ObjectList>
<Hmi.Screen.Property Name="Layer" AggregationName="Properties" ID="77">
<AttributeList>
<Value>0</Value>
</AttributeList>
</Hmi.Screen.Property>
<Hmi.Screen.Property Name="Left" AggregationName="Properties" ID="78">
<AttributeList>
<Value>264</Value>
</AttributeList>
</Hmi.Screen.Property>
<Hmi.Screen.Property Name="Top" AggregationName="Properties" ID="79">
<AttributeList>
<Value>48</Value>
</AttributeList>
</Hmi.Screen.Property>
<Hmi.Screen.Property Name="FitToLargest" AggregationName="Properties" ID="84">
<AttributeList>
<Value>false</Value>
</AttributeList>
</Hmi.Screen.Property>
</ObjectList>
</Hmi.Screen.TextField>
This is the part of it we want to delete OR set the value from false
to true
(your choice what's easier):
<Hmi.Screen.Property Name="FitToLargest" AggregationName="Properties" ID="84">
<AttributeList>
<Value>false</Value>
</AttributeList>
</Hmi.Screen.Property>
This part of code is found in every textfield, but with a different value for the attribute ID. We want to delete it for every textfield.
We already have this:
XDocument xml = XDocument.Load(loadLocation);
xml.Descendants().Elements("Hmi.Screen.Property")
.Where(e => e.Attribute("Name=").Value == "FitToLargest")
.Remove();
xml.Save(loadLocation);
We found it on stackoverflow, but it gives this error:
Error 1 A local variable named 'e' cannot be declared in this scope because it would give a different meaning to 'e', which is already used in a 'parent or current' scope to denote something else C:\Users\*****\*****\*****\Projects\Converter\Converter\Form1.cs 211 37 Converter
We can remove the error by changing the e
to for example eJbou
(Jbou are my initials)
We hope somebody can help us by telling what the error means, or help us by give a code that does work.