Xml updating with linq not working when quering

Posted by user1734230 on Stack Overflow See other posts from Stack Overflow or by user1734230
Published on 2012-10-10T09:27:10Z Indexed on 2012/10/10 9:37 UTC
Read the original article Hit count: 137

Filed under:
|
|

I have problem i'm trying to update a specific part of the XML with the linq query but it doesn't work. So i an xml file:

<?xml version="1.0" encoding="utf-8"?>
<DesignConfiguration>
  <Design name="CSF_Packages">
    <SourceFolder>C:\CSF_Packages</SourceFolder>
    <DestinationFolder>C:\Documents and Settings\xxx</DestinationFolder>
    <CopyLookups>True</CopyLookups>
    <CopyImages>False</CopyImages>
    <ImageSourceFolder>None</ImageSourceFolder>
    <ImageDesinationFolder>None</ImageDesinationFolder>
  </Design>
</DesignConfiguration>

I want to select the part where the part where there is Design name="somethning" and get the descendants and then update the descendants value that means this part:

    <SourceFolder>C:\CSF_Packages</SourceFolder>
    <DestinationFolder>C:\Documents and Settings\xxx</DestinationFolder>
    <CopyLookups>True</CopyLookups>
    <CopyImages>False</CopyImages>
    <ImageSourceFolder>None</ImageSourceFolder>
    <ImageDesinationFolder>None</ImageDesinationFolder>

I have this code:

        XDocument configXml = XDocument.Load(configXMLFileName);

        var updateData = configXml.Descendants("DesignConfiguration").Elements().Where(el => el.Name == "Design" &&
            el.Attribute("name").Value.Equals("AFP_GRAFIKA")).FirstOrDefault();

        configXml.Save(configXMLFileName);

I'm getting the null data in the updateData varibale. When I'm trying the Descendat's function through QuickWatch it also returns a null value. When I'm checking the configXML variable it has data that is my whole xml. What am I doing wrong?

© Stack Overflow or respective owner

Related posts about c#

Related posts about Xml