0

I have this XML file where I want to change the value of fit-to-largest from false to true. Like this:

<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>

From this code I want to change this part form this:

<Hmi.Screen.Property Name="FitToLargest" AggregationName="Properties" ID="84">
    <AttributeList>
      <Value>false</Value>
    </AttributeList>
</Hmi.Screen.Property>

to this:

<Hmi.Screen.Property Name="FitToLargest" AggregationName="Properties" ID="84">
    <AttributeList>
      <Value>true</Value>
    </AttributeList>
</Hmi.Screen.Property>

(false becomes true)

I want to change this by loading the XML file (I know how) and then find and replace the false to true.

This part of code is found in every textfield, but with a different value for the attribute ID. I want to change it for every textfield.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • Load the XML file into an XDocument, find the property XElement where the attribute "Name" equals "FitToLargest", find the value XElement. Sounds like a trivial LINQ-to-XML query. What part do you need help with? What have you tried so far? – dtb Aug 30 '13 at 13:08
  • I tried to delete this part but it didn't work, I used this code: XDocument xml = XDocument.Load(loadLocation); xml.Descendants().Elements("Hmi.Screen.Property") .Where(e => e.Attribute("Name=").Value == "FitToLargest") .Remove(); xml.Save(loadLocation); but I thought it would be easier just to change the false to true, because it does the same as deleting it. – aRandomStudent Aug 30 '13 at 13:14
  • This is basically [a repost](http://stackoverflow.com/q/18527262). Don't do that, stick to your question and improve it. You are still using `"Name="`, read the comments. You already have an answer. – H H Aug 30 '13 at 13:26
  • Yh sorry i copied the version where i didnt change it – aRandomStudent Aug 30 '13 at 13:39

0 Answers0